Meredith Jantzen
2011-Sep-22 13:59 UTC
[R] negative binomial GAMM with variance structures
Hello, I am having some difficulty converting my gam code to a correct gamm code, and I'm really hoping someone will be able to help me. I was previously using this script for my overdispersed gam data: M30 <-gam(efuscus~s(mic, k=7) +temp +s(date)+s(For3k, k=7) + pressure+ humidity, family=negbin(c(1,10)), data=efuscus) My gam.check gave me the attached result. In order to deal with my heterogeneity, I need to switch over to a gamm structure and use at least one, but possibly multiple, variance structures, and I am starting by applying varPower to my temperature covariate. (Efuscus is my square root transformed response variable). Here is the code I have for the gamm: K1 <-(efuscus~s(mic, k=7) +temp +s(date)+s(For3k, k=7) + pressure+ humidity+ windspeed + year) M17.4A <-gamm(K1, method="REML", family=negbin(c(1,10), data=efuscus, weights=varPower(form=~temp)) With my various versions of the script, the two error messages I have been getting repeatedly are: Error in eval(expr, envir, enclos) : object 'temp' not found, and Error: unexpected symbol in: "M17.4A <-gamm(K1, method="REML", family=negbin(c(1,10), data=efuscus, weights=varPower(form=~temp))" I know I must be missing something obvious that is causing my script not to work...I've been looking at both Wood (2006) and Zuur's Mixed Models book for examples but none of them are completely the same as my situation, which is causing me to get tripped up. Am I defining my negative binomial family correctly for the situation? Do I need to somehow define the variance term before I apply it? Thank you very much. I appreciate your time and patience. Meredith
gamm can't estimate the theta parameter for a negative binomial automatically. It can only work with fixed user supplied values for theta (i.e. negbin(2.3) should work, but negbin(c(1,10)) won't). Is negative binomial the only thing you can use here (it doesn't seem like the most natural choice for a variable that's been sqrt transformed)? Simon ps. Your checking plot didn't come through --- you can send it offline, if you want. On 09/22/2011 02:59 PM, Meredith Jantzen wrote:> Hello, > > I am having some difficulty converting my gam code to a correct gamm code, and I'm really hoping someone will be able to help me. > > I was previously using this script for my overdispersed gam data: > > M30<-gam(efuscus~s(mic, k=7) +temp +s(date)+s(For3k, k=7) + pressure+ humidity, family=negbin(c(1,10)), data=efuscus) > > My gam.check gave me the attached result. In order to deal with my heterogeneity, I need to switch over to a gamm structure and use at least one, but possibly multiple, variance structures, and I am starting by applying varPower to my temperature covariate. (Efuscus is my square root transformed response variable). > > Here is the code I have for the gamm: > > K1<-(efuscus~s(mic, k=7) +temp +s(date)+s(For3k, k=7) + pressure+ humidity+ windspeed + year) > M17.4A<-gamm(K1, method="REML", family=negbin(c(1,10), data=efuscus, weights=varPower(form=~temp)) > > With my various versions of the script, the two error messages I have been getting repeatedly are: Error in eval(expr, envir, enclos) : object 'temp' not found, and Error: unexpected symbol in: "M17.4A<-gamm(K1, method="REML", family=negbin(c(1,10), data=efuscus, weights=varPower(form=~temp))" > > I know I must be missing something obvious that is causing my script not to work...I've been looking at both Wood (2006) and Zuur's Mixed Models book for examples but none of them are completely the same as my situation, which is causing me to get tripped up. > > Am I defining my negative binomial family correctly for the situation? Do I need to somehow define the variance term before I apply it? > > Thank you very much. I appreciate your time and patience. > Meredith > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]