Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in fcor() for nonlinear model #1666

Open
abstrathe opened this issue Jun 17, 2024 · 0 comments
Open

Error in fcor() for nonlinear model #1666

abstrathe opened this issue Jun 17, 2024 · 0 comments
Labels
Milestone

Comments

@abstrathe
Copy link

Dear brms experts,

I get the following error "Error in get(covars[i], data) : object 'R' not found" when fitting a nonlinear model with known residual covariance matrix. Below, I have created a small simulated example that recreates the error. Note, that brms() runs smoothly for a linear model, using the sampling error covariance matrix and fits the nonlinear model using the sampling standard error.

I used brms_2.21.1 under R version 4.3.1.

Any ideas?

Many thanks in advance,
Anders Strathe


Simulated example
library(brms)

Simulated aggregated data
sim = data.frame(y=c(-2.56,-4.573,-7.622,-9.656,-10.792,-11.705,-12.312,-12.645,-12.977,-12.77),
se=c(0.201,0.26,0.388,0.48,0.61,0.715,0.853,1.033,1.155,1.218),
time=c(2,4,8,12,16,20,28,36,44,52) )
str(sim)
sampling error covariance matrix
R = matrix(c(0.04,0.042,0.055,0.062,0.065,0.075,0.061,0.071,0.083,0.085,0.042,0.067,0.087,0.095,0.11,0.126,0.126,0.138,0.152,0.156,0.055,0.087,0.151,0.172,0.202,0.236,0.249,0.272,0.286,0.283,0.062,0.095,0.172,0.231,0.275,0.314,0.334,0.372,0.394,0.394,0.065,0.11,0.202,0.275,0.373,0.42,0.463,0.532,0.569,0.565,0.075,0.126,0.236,0.314,0.42,0.511,0.576,0.664,0.713,0.705,0.061,0.126,0.249,0.334,0.463,0.576,0.727,0.842,0.897,0.904,0.071,0.138,0.272,0.372,0.532,0.664,0.842,1.067,1.165,1.194,0.083,0.152,0.286,0.394,0.569,0.713,0.897,1.165,1.335,1.382,0.085,0.156,0.283,0.394,0.565,0.705,0.904,1.194,1.382,1.483), 10, 10)

Fit linear discrete time-course model
fit <- brm(y ~ 0 + factor(time) + fcor(R),
data = sim,
data2 = list(R = R),
prior = prior(constant(1), class="sigma"),
control = list(adapt_delta = 0.95, max_treedepth = 20),
iter = 2000, chains = 2, cores = 2)

fit

Fit nonlinear time-course model, using sampling standard error
nonlin <- brm(bf(y | se(se) ~ emaxT*(1 - exp( -exp(kT)*time )),
emaxT ~ 1, kT ~ 1,
nl=TRUE),
data = sim,
prior = prior(normal(-10, 100), nlpar = "emaxT") +
prior(normal(-2.5,100), nlpar = "kT"),
control = list(adapt_delta = 0.95, max_treedepth = 20),
iter = 2000, chains = 2, cores = 2)
nonlin

Fit nonlinear time-course model, including sampling covariance matrix
nonlin2 <- brm(bf(y ~ emaxT*(1 - exp( -exp(kT)*time )) + fcor(R),
emaxT ~ 1, kT ~ 1,
nl=TRUE),
data = sim,
data2 = list(R = R),
prior = prior(normal(-10, 100), nlpar = "emaxT") +
prior(normal(-2.5,100), nlpar = "kT") +
prior(constant(1), class="sigma"),
control = list(adapt_delta = 0.95, max_treedepth = 20),
iter = 2000, chains = 2, cores = 2)
nonlin2

@paul-buerkner paul-buerkner added this to the brms 2.22.0 milestone Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants