Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Last active October 3, 2021 18:21
Show Gist options
  • Save MJacobs1985/ee1008166497ed1ad17d3dd3190fb19c to your computer and use it in GitHub Desktop.
Save MJacobs1985/ee1008166497ed1ad17d3dd3190fb19c to your computer and use it in GitHub Desktop.
NLMixed in R
## Include identification variable - sample. This will influence if and how to split U, D or Kd
# Simplest way --> Split analysis --> SMALL model is the pooled data. LARGE model is the separate data combined
try<-nls(formula=formuDMres, data=(Grass[complete.cases(Grass$y),]),start=list(U=19.7,D=52,Kd=0.035))
try.SS1<-nls(formula=formuDMres, data=Grass[Grass$Standard.sample=="1",],start=list(U=19.7,D=52,Kd=0.035))
try.SS2<-nls(formula=formuDMres, data=Grass[Grass$Standard.sample=="2",],start=list(U=19.7,D=52,Kd=0.035))
summary(try.SS1)
summary(try.SS2)
resid.small<-resid(try)
resid.big<-c(resid(try.SS1),resid(try.SS2))
df.small<-summary(try)$df
df.big<-(summary(try.SS1)$df+summary(try.SS2)$df)
F.value <- ((sum(resid.small^2)-sum(resid.big^2))/(df.big[1]-df.small[1])) / (sum(resid.big^2)/(df.big[2]))
P.value <- pf(F.value , (df.big[1]-df.small[1]), df.big[2], lower.tail = FALSE) # using F distribution to test F value
F.value; P.value # For sure indication to use identification variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment