Last active
October 3, 2021 18:19
-
-
Save MJacobs1985/6c534f6333676904c08d134eefd49c86 to your computer and use it in GitHub Desktop.
NLMIXED in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### NLIN - Use identification variable to already look into NLMixed | |
| # Simple model, ignoring groups | |
| try1<-nls(y~f1(x,U,D,Kd), data=(Grass[complete.cases(Grass$y),]),start=list(U=19.7,D=52,Kd=0.035)) | |
| summary(try1) | |
| # Full model with different parameters for the two groups (which makes it the larger model, because of more parameters) | |
| try2<-nls(y~f1(x, | |
| U[Standard.sample2], | |
| D[Standard.sample2], | |
| Kd[Standard.sample2]), | |
| data=(Grass[complete.cases(Grass$y),]), | |
| start=list(U=rep(19.7,2),D=rep(52,2),Kd=rep(0.035,2))) | |
| summary(try2) | |
| # Assume Kd similar across groups | |
| try3<-nls(y~f1(x, | |
| U[Standard.sample2], | |
| D[Standard.sample2], | |
| Kd), | |
| data=(Grass[complete.cases(Grass$y),]), | |
| start=list(U=rep(19.7,2),D=rep(52,2),Kd=0.035)) | |
| # Residual plots | |
| p1<-plot(try1);p2<-plot(try2);p3<-plot(try3); grid.arrange(p1,p2,p3,ncol=3) | |
| p1<-qqnorm(try1);p2<-qqnorm(try2);p3<-qqnorm(try3); grid.arrange(p1,p2,p3,ncol=3) | |
| nlstools::overview(try3) # shows t based confidence intervals | |
| confint(try3) # better confidence intervals then provided via overview (uses profiling) | |
| confint.default(try3) | |
| nlstools::plotfit(try1, smooth=TRUE) | |
| try3.resid<-nlstools::nlsResiduals(try3) | |
| plot(try3.resid) | |
| plot(try3) | |
| qqnorm(try3) | |
| head(residuals(try3)[-1]) | |
| head(residuals(try3.resid)) | |
| plot(residuals(try3), c(residuals(try3)[-1],NA)) | |
| plot(try3.resid,which=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment