[R] interaction term by a factor group in gamm4

Maria Lathouri mlathouri at yahoo.gr
Tue Jan 23 12:57:35 CET 2018


Dear all, 
I am writing as I would really need your help on the problem with gamm4. I have tried to find a solution online but I wasn't very successful. 
I am running a gamm4 model with an interaction between two variable using the tensor term, t2. I have a group variable (super end group) with six factors; I would like to run the model to see the how the interaction term varies across the factor levels and get the plot for each factor in one page. Here is my code but I get the following message 

dat<-read.table("dat.txt", header=TRUE) 

str(dat) 
#'data.frame':    11744 obs. of  11 variables: 
#$ WATERBODY_ID          : Factor w/ 1994 levels "GB102021072830",..: 1 1 2 2 2 3 3 3 4 4 5 5 5 5 5 6 ... 
#$ SITE_ID              : int  157166 157166 1636 1636 1636 1635 1635 1635 134261 1631 65383 65383 65383 111828 ... 
#$ Year                  : int  2011 2014 2013 2006 2003 2002 2013 2005 2013 2006 2011 2005 2004 ... 
#$ ResidualQ95          : num  100 100 80 80 80 98 98 98 105 105 101 101 130 120 120 ... 
#$ LIFE.OE_spring        : num  1.02 1.03 1.02 1.06 1.06 1.07 1.12 1.05 1.14 1.05 1.09 1.14 1.04 0.97 0.98 ... 
#$ super.end.group      : Factor w/ 6 levels "B","C","D","E",..: 1 1 3 3 3 2 2 2 4 4 ... 
#$ X.urban.suburban      : num  0 0 0.07 0.07 0.07 0.53 0.53 0.53 8.07 8.07 0.27 0.27 0.27 0.27 0.27 0.72 ... 
#$ X.broadleaved_woodland: num  2.83 2.83 10.39 10.39 10.39 7.72 7.72 21.15 21.15 14.44 14.44 ... 
#$ X.CapWks              : num  0 0 0 0 0 0 0 0 0 0 8.11 8.11 8.11 0 0 0 42.06 42.06 7.08 0.2 ... 
#$ Hms_Poaching          : num  0 0 10 10 10 0 0 0 0 10 10 20 40 5 30 15 15 0 0 0 50 50 ... 
#$ Hms_Rsctned          : num  0 0 0 0 0 0 0 0 0 0 2480 800 1960 1160 740 0 0 960 ... 

library(gamm4) 

model<-gamm4(LIFE.OE_spring~s(ResidualQ95, by=super.end.group)+t2(ResidualQ95, Hms_Rsctned, by=super.end.group)+Year +Hms_Poaching +X.broadleaved_woodland +X.urban.suburban +X.CapWks, data=dat, random=~(1|WATERBODY_ID/SITE_ID)) 
#Warning messages: 
#1: In optwrap(optimizer, devfun, getStart(start, rho$lower, rho$pp),  : 
#  convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded 
#2: In optwrap(optimizer, devfun, opt$par, lower = rho$lower, control = control,  : 
#  convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded 

I also tried the following but I got the same message as before. 

model<-gamm4(LIFE.OE_spring~s(ResidualQ95)+t2(ResidualQ95, Hms_Rsctned, by=super.end.group)+Year+ Hms_Poaching +X.broadleaved_woodland +X.urban.suburban +X.CapWks, data=dat, random=~(1|WATERBODY_ID/SITE_ID)) 
#fixed-effect model matrix is rank deficient so dropping 1 column / coefficient 

#Warning messages: 
#1: In optwrap(optimizer, devfun, getStart(start, rho$lower, rho$pp),  : 
#  convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded 
#2: In optwrap(optimizer, devfun, opt$par, lower = rho$lower, control = control,  : 
#  convergence code 1 from bobyqa: bobyqa -- maximum number of function evaluations exceeded 

When I tried to plot, I got the following error: 
plot(model$gam, page=1) 
#Error in plot.window(...) : need finite 'ylim' values 
#In addition: Warning messages: 
#  1: In min(ll, na.rm = TRUE) : 
#  no non-missing arguments to min; returning Inf 
#  2: In max(ul, na.rm = TRUE) : 
#  no non-missing arguments to max; returning -Inf 

I would really appreciate your help. My dataset is quite large that is why I have used the str() for you to get an idea; I have attached a txt file as well as a sample of my dataset but I have trimmed it a lot so it is even smaller to fit the email size. 

Thank you very much. 

Best, 
Maria
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dat.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20180123/cae70e5b/attachment.txt>


More information about the R-help mailing list