[R-sig-ME] nlmer function Error in devfun(rho$pp$theta) error
Abdullah içen
@bdu||@h|cen @end|ng |rom gm@||@com
Mon Nov 9 18:40:13 CET 2020
Hi all,
Hope you are well and healthy, everything is fine on these bad days.
I want to model my data using nlmer function in lme4 package but i got the
following error.
*Error in devfun(rho$pp$theta) : step factor reduced below 0.001 without
reducing pwrss*
This is my nonlinear function:
*NLSite <- function(PSAr, Vs30, h800, f5, b1, b2, b3, c){ #Linear term
.exprN1 <- ifelse(Vs30>1000, 1000/760, Vs30/760) .exprN2 <- log(.exprN1)
.valueN <- b1*.exprN2 # Depth-to-rock term (in log) # in SD18 they are
estimated from CY08 equation for Z1 h800[h800<1]<-1 .exprZ1 <-
ifelse(Vs30>=760, 1, h800) .exprZ2 <- log(.exprZ1) .valueZ <- b2*.exprZ2
#Nonlinear term .f5 <- f5 .exprNL1 <- ifelse(Vs30>760, 760-360,
Vs30-360) .exprNL2 <- .f5*.exprNL1 .exprNL3 <- exp(.exprNL2) .exprNL4 <-
.f5*400 .exprNL5 <- exp(.exprNL4) .exprNL6 <- .exprNL3 - .exprNL5
.exprNL7 <- PSAr/c .exprNL8 <- 1+.exprNL7 #log(1+PSAr/c) .exprNL9 <-
log(.exprNL8) .valueNL <- b3*.exprNL9*.exprNL6 .value <- .valueN +
.valueZ + .valueNL .grad <- array(0, c(length(.value), 4L), list(NULL,
c("b1", "b2", "b3","c"))) ## e1 ## ## b1, b2 ,b3 ## .grad[, "b1"] <-
.exprN2 .grad[, "b2"] <- .exprZ2 .grad[, "b3"] <- .exprNL9*.exprNL6
.grad[, "c"] <- .exprNL6*((1/(.exprNL8))*(-.exprNL7/c)) attr(.value,
"gradient") <- .grad .value}*
And i use the following code for running the nlmer function (by the way i
don't use intercept in my model and just writing 0|EQID is not accepted so
i wrote random effects (b1 + b2 + b3 + c + 0|EQID) hope that is true)
* nlmer_site <- nlmer( log(PSAm) ~ NLSite(PSAr, Vs30, h800, f5, b1, b2, b3,
c) ~ 0+ b1 + b2 + b3 + c + (b1 + b2 + b3 + c + 0|EQID) + (b1 + b2 + b3 + c
+ 0|STID), data = data.frame(data),
nlmerControl(optimizer = "Nelder_Mead"), start = c( b1 = 0.2, b2 = 0.5,
b3 =-1, c = 0.1), nAGQ = 1L)*
when i change my nonlinear term c with constant value and run it (
NLSite(PSAr, Vs30, h800, f5, b1, b2, b3) like this) works without error. I
also compared it with lmer (without nonlinear parameter, taking c as
constant) both gave almost (correct till 10^-6) the same result.
To explain my data. PSAr, Vs30, h800, f5 are my input values. PSAr is
acceleration values, Vs is velocity, h800 is depth and f5 is a parameter i
used. Using these inputs i want to predict nonlinear site amplification b1
b2 and b3 are linear parameters c is nonlinear which is log((PSAr+c)/c)
taking c as constant doesn't give any error so there is no problem with my
data. I used starting values from the previous studies which i expected to
be close to my values but i also didn't work. In the previous studies for
deriving the f5 and b1 b2 b3 parameters it's assumed to be constant and
taken as 0.1 but also there are c values derived using this nonlinear
function.
Also i want to say that the following code below works well with my data
without any error. so problem is about my nonlinear function.
*GMPE <- function(M,R,Mref,Mh,Rref,e1,b1,b2,b3,c1,c2,c3,h) { ## FM ##
.Mh <- Mh .exprM1 <- M - .Mh .exprM2 <- .exprM1 ^ 2 .exprM3 <- b1 *
.exprM1 + b2 * .exprM2 .exprM4 <- b3 * .exprM1 .valueFM <- ifelse(M<=.Mh,
.exprM3, .exprM4) ##FD ## .Mref <- Mref .Rref <- Rref .exprD1 <- M -
.Mref .exprD2 <- c1 + c2 * .exprD1 # [c1 + c2(M-Mref)] .exprD3 <- R^2 +
h^2 # [Rjb^2 + h^2] .exprD4 <- sqrt(.exprD3) # [sqrt[Rjb^2 + h^2]]
.exprD5 <- .exprD4/.Rref # [sqrt[Rjb^2 + h^2]/Rref] .exprD6 <-
log(.exprD5) # LN[sqrt[Rjb^2 + h^2]/Rref] .exprD7 <- .exprD4 - .Rref #
[sqrt[Rjb^2 + h^2] - Rref] .valueFD <- .exprD2 * .exprD6 + c3 * .exprD7
## Value ## .value <- e1 + .valueFD + .valueFM ## Gradient ## .grad <-
array(0, c(length(.value), 8L), list(NULL, c("e1","b1", "b2", "b3","c1",
"c2", "c3", "h"))) ## e1 ## .grad[, "e1"] <- 1.0 ## b1, b2 ,b3
## .grad[, "b1"] <- ifelse(M<=.Mh,.exprM1,0) .grad[, "b2"] <-
ifelse(M<=.Mh,.exprM2,0) .grad[, "b3"] <- ifelse(M<=.Mh,0,.exprM1) ##
c1, c2 ,c3, h ## .grad[, "c1"] <- .exprD6 .grad[, "c2"] <- .exprD1 *
.exprD6 .grad[, "c3"] <- .exprD7 .grad[, "h"] <- .exprD2 * (h/.exprD3) +
c3 * (h /.exprD4) attr(.value, "gradient") <- .grad .value }data$Mref
<- 4data$Mh <- 5data$Rref <- 100nlmer_gmpe <- nlmer( log(PSA) ~ GMPE(Mw,
RJB, Mref,Mh,Rref,e1,b1,b2,b3,c1,c2,c3,h) ~ e1 + b1 + b2 + b3 + c1 + c2 +
c3 + h + (e1 + 0|EQID) + (e1+0|STID), data =
data.frame(data), start = c(e1 = 3, b1 = 1, b2 = 1, b3 =1, c1 = 1, c2 =
1, c3 = 1, h = 5), nAGQ = 1L)fixef(nlmer_gmpe)Have nice days,*
Abdullah
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list