Multivariate nonlinear model: Not sure what initial values to use

I am running my first nonlinear model in brms, and it is also multivariate. I am new to brms, so forgive me if I am missing something obvious. When I try to run this model, the parameter what1 is not recognized as a model parameter. Thank you if you can see what I am doing wrong. The data I have looks like this:

head(Obs)
x1 x2 x3 tx1 tx2 tx3 y1 y2 y3 yt1 yt2 yt3 E
1 10 10 10 0.4 0.5000000 0.6 18 17 15 0.4 0.4952381 0.6 0.1
2 18 17 15 0.4 0.4952381 0.6 31 28 22 0.4 0.4905329 0.6 0.1
3 31 28 22 0.4 0.4905329 0.6 53 45 32 0.4 0.4858837 0.6 0.1
4 53 45 32 0.4 0.4858837 0.6 89 70 46 0.4 0.4812898 0.6 0.1
5 89 70 46 0.4 0.4812898 0.6 143 105 64 0.4 0.4767507 0.6 0.1
6 143 105 64 0.4 0.4767507 0.6 219 147 85 0.4 0.4722655 0.6 0.1

mod_N1 <- bf(y1 ~ (((what1*exp((-(((w + (1-h21)*P) / (P+w)) * (E-tx1))^2) / (2*(P+w))))*x1) / (1 + a11*x1 + a12*x2 + a13*x3)),
             a11~1,a12~1,a13~1,what1~1,w~1,P~1,h21~1,
             nl=TRUE)

mod_N2 <- bf(y2 ~ (((what2*exp((-(((w + (1-h22)*P) / (P+w)) * (E-tx2))^2) / (2*(P+w))))*x2) / (1 + a22*x2 + a21*x1 + a23*x3)),
             a22+a21+a23+what2+w+P+h22~1,
             nl=TRUE)

mod_N3 <- bf(y3 ~ (((what3*exp((-(((w + (1-h23)*P) / (P+w)) * (E-tx3))^2) / (2*(P+w))))*x3) / (1 + a33*x3 + a31*x1 + a32*x2)),
             a33+a31+a32+what3+w+P+h23~1,
             nl=TRUE)

p <- get_prior(mod_N1 + mod_N2 + mod_N3, data = Obs)
# N1
p$prior[5] <- "beta(1, 10)" # a11
p$prior[7] <- "beta(1, 10)" # a12
p$prior[9] <- "beta(1, 10)" # a13
p$prior[11] <- "beta(2, 2)" # h21
p$prior[13] <- "gamma(0.5, 1)" # P
p$prior[15] <- "gamma(0.5, 1)" # w
p$prior[17] <- "normal(0, 2)" # what1
# N2
p$prior[20] <- "beta(1, 10)" # a21
p$prior[22] <- "beta(1, 10)" # a22
p$prior[24] <- "beta(1, 10)" # a23
p$prior[26] <- "beta(2, 2)" # h22
p$prior[28] <- "gamma(0.5, 1)" # P
p$prior[30] <- "gamma(0.5, 1)" # w
p$prior[32] <- "normal(0, 2)" # what2
# N3
p$prior[35] <- "beta(1, 10)" # a31
p$prior[37] <- "beta(1, 10)" # a32
p$prior[39] <- "beta(1, 10)" # a33
p$prior[41] <- "beta(2, 2)" # h23
p$prior[43] <- "gamma(0.5, 1)" # P
p$prior[45] <- "gamma(0.5, 1)" # w
p$prior[47] <- "normal(0, 2)" # what3

fit <- brm(mod_N1 + mod_N2 + mod_N3, data = Obs, chains = 2,inits=0,prior=p,family=gaussian(link = "identity"))

The error message is:

SAMPLING FOR MODEL ‘34a348d533a189f4c70d5b2c02df0bc6’ NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: multi_normal_cholesky_lpdf: Location parameter[1] is nan, but must be finite! (in ‘model70c542728a9c_34a348d533a189f4c70d5b2c02df0bc6’ at line 182)

[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”
error occurred during calling the sampler; sampling not done
I have attached a .txt file with the data.

*OperatingSystem:Mac OS 10.13.6
*brms Version:2.9.0Obs.txt (83.7 KB)

I can’t easily see where what1 is coming from. It’s not in the data file. Are you pulling it from somewhere else?

It’s meant as a parameter to be estimated. I’ve tried to rewrite the model and set some priors, but I am still receiving an error I am unsure how to resolve.

1 Like

Oh ok I see. Sorry! Misread the model.

I’ve made a lot of changes, and I can’t see where to go next. I don’t really understand what underlies this error message:

mod_N1 <- bf(y1 ~ (((what1exp((-(((w + (1-h21)P) / (P+w)) * (E-tx1))^2) / (2(P+w))))x1) / (1 + a11x1 + a12x2 + a13*x3)),
a11~1,a12~1,a13~1,what1~1,w~1,P~1,h21~1,
nl=TRUE)

mod_N2 <- bf(y2 ~ (((what2exp((-(((w + (1-h22)P) / (P+w)) * (E-tx2))^2) / (2(P+w))))x2) / (1 + a22x2 + a21x1 + a23*x3)),
a22+a21+a23+what2+w+P+h22~1,
nl=TRUE)

mod_N3 <- bf(y3 ~ (((what3exp((-(((w + (1-h23)P) / (P+w)) * (E-tx3))^2) / (2(P+w))))x3) / (1 + a33x3 + a31x1 + a32*x2)),
a33+a31+a32+what3+w+P+h23~1,
nl=TRUE)

p <- get_prior(mod_N1 + mod_N2 + mod_N3, data = Obs)

N1

p$prior[4+1] <- “beta(1, 10)” # a11
#p$bound[5] <- “0,1” # a11
p$prior[6+1] <- “beta(1, 10)” # a12
#p$bound[7] <- “0,1” # a12
p$prior[8+1] <- “beta(1, 10)” # a13
#p$bound[9] <- “0,1” # a13
p$prior[10+1] <- “beta(2, 2)” # h21
#p$bound[11] <- “0,1” # h21
p$prior[12+1] <- “gamma(0.5, 1)” # P
#p$bound[5] <- “0” # P
p$prior[14+1] <- “gamma(0.5, 1)” # w
p$prior[16+1] <- “normal(0, 2)” # what1

N2

p$prior[19+1] <- “beta(1, 10)” # a21
p$prior[21+1] <- “beta(1, 10)” # a22
p$prior[23+1] <- “beta(1, 10)” # a23
p$prior[25+1] <- “beta(2, 2)” # h22
p$prior[27+1] <- “gamma(0.5, 1)” # P
p$prior[29+1] <- “gamma(0.5, 1)” # w
p$prior[31+1] <- “normal(0, 2)” # what2

N3

p$prior[34+1] <- “beta(1, 10)” # a31
p$prior[36+1] <- “beta(1, 10)” # a32
p$prior[38+1] <- “beta(1, 10)” # a33
p$prior[40+1] <- “beta(2, 2)” # h23
p$prior[42+1] <- “gamma(0.5, 1)” # P
p$prior[44+1] <- “gamma(0.5, 1)” # w
p$prior[46+1] <- “normal(0, 2)” # what3

chains <- 2
inits_drift1 <- list(a11 = 0.0005,a12 = 0.0005,a13 = 0.0005,a21 = 0.0005,a22 = 0.0005,a23 = 0.0005,a31 = 0.0005,a32 = 0.0005,a33 =0.0005,P=.01,w=.5,h21=0,h22=0,h23=0,what1=2,what2=2,what3=2)
inits_drift2 <- list(a11 = 0.005,a12 = 0.005,a13 = 0.005,a21 = 0.005,a22 = 0.005,a23 = 0.005,a31 = 0.005,a32 = 0.005,a33 =0.005,P=.05,w=.9,h21=.5,h22=.5,h23=.5,what1=1.5,what2=1.5,what3=1.5)
inits_drift <- list(inits_drift1,inits_drift2)

fit <- brm(mod_N1 + mod_N2 + mod_N3, data = Obs, chains = 2,prior=p,inits=inits_drift,init_r=0.00001,iter=200000,control = list(adapt_delta = 0.99),family=gaussian(link=“log”))

ERROR:



Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: beta_lpdf: Random variable[1] is -9.09703e-06, but must be >= 0! (in ‘model5e84762bf0b9_823ce635e77c07d423e9f185d5e8cf10’ at line 152)

Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: beta_lpdf: Random variable[1] is -2.39877e-06, but must be >= 0! (in ‘model5e84762bf0b9_823ce635e77c07d423e9f185d5e8cf10’ at line 171)

Chain 1:
Chain 1: Initialization between (-1e-05, 1e-05) failed after 100 attempts.
Chain 1: Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”
error occurred during calling the sampler; sampling not done