Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Last active October 3, 2021 09:27
Show Gist options
  • Save MJacobs1985/981df24fb2cc33f6a2de76688c489f99 to your computer and use it in GitHub Desktop.
Save MJacobs1985/981df24fb2cc33f6a2de76688c489f99 to your computer and use it in GitHub Desktop.
NLMIXED in R
try.nlm2<-nlme(y~U+D*exp(-(Kd*x)),
data=Grass_compl,
fixed=U+D+Kd~1,
random=U+D+Kd~1|Trial/Cow,
start=c(U=20,D=50.88,Kd=0.02698),
method="ML",
control=nlmeControl(maxIter=1000, msMaxIter = 100))
try.nlm3<-nlme(y~U+D*exp(-(Kd*x)),
data=Grass_compl,
fixed=U+D+Kd~1,
random=U+D+Kd~1|Trial/Cow/Replicate,
start=c(U=20,D=50.88,Kd=0.02698),
method="ML",
control=nlmeControl(maxIter=1000, msMaxIter = 100)) # Can't run, singular precision matrices
try.nlm4<-nlme(y~U+D*exp(-(Kd*x)),
data=Grass_compl,
fixed=U+D+Kd~1,
random=U+D+Kd~1|id,
start=c(U=20,D=50.88,Kd=0.02698),
method="ML",
control=nlmeControl(maxIter=1000, msMaxIter = 100))
try.nlm5<-nlme(y~U+D*exp(-(Kd*x)),
data=Grass_compl,
fixed=U+D+Kd~1,
random=U+D+Kd~1|Cow,
start=c(U=20,D=50.88,Kd=0.02698),
method="ML",
control=nlmeControl(maxIter=1000, msMaxIter = 100))
nlm<-nlme(y~U+D*exp(-(Kd*x)),
data=Grass_new,
fixed=U+D+Kd~1,
random=U+D+Kd~1,
start=c(U=20,D=50.88,Kd=0.02698),
method="ML",
control=nlmeControl(maxIter=1000000, msMaxIter = 1000))
nlm_auto<-nlme(y~U+D*exp(-(Kd*x)),
data=Grass_new,
fixed=U+D+Kd~1,
random=U+D+Kd~1,
start=c(U=20,D=50.88,Kd=0.02698),
correlation = corARMA(c(-0.4,-0.2,0.3), p=0, q=3, form=~1|id),
method="ML",
control=nlmeControl(maxIter=1000000, msMaxIter = 1000))
# Compare Nested Models
anova(try.nlm1, try.nlm2)
anova(try.nlm1,try.nlm5,try.nlm4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment