Julie Lee-Yaw
2019-Feb-26 22:36 UTC
[R] Help formulating gamm with repeated measures and spatial autocorrelation using mgcv package
(Also posted on StackExchange but submitting to R-help to reach more potential experts)I am using the gamm function in the mgcv package in R to specify a model that predicts abundance with respect to elevation and year based on repeated measures from several sites. My overarching question is how abundance changes over elevation, knowing and accounting for the fact that it also changes over time. GAMM is used because I do not want to restrict the relationship of either elevation or year with abundance to be linear. I expect the data to be spatially autocorrelated within years (sites closer together will have more similar values than sites further apart within each year) and would like to account for this. I'm having trouble figuring out the proper full formulation of the GAMM. The variables are: 1) abundance (continuous response) 2) elevation (numeric, continuous predictor) 3) year (numeric, continuous predictor as we expect a gradual change in abundance over time) 4) spatial autocorrelation term (based on the lat/long of the sites where data were collected) 5) site (random factor) The model formulation I have come up with is: model<-gamm(abundance ~ s(elevation, bs = "tp")+s(year, bs = "tp"), correlation=corSpher(form = ~ y+x|year), random=list(site=~1), data=input.data) My questions are: Is the repeated measures nature of the data adequately accounted for here or do I also need to include year in my random effects (nest site in year)? Have I properly taken year into account in my spatial autocorrelation term? Finally, when running this model, I get an error and a warning:Error in corFactor.corSpatial(object):??Na/NaN/Inf in foreign function call (arg 1)?In addition: Warning message:?In min(unlist(attr(object,"covariate"))):?no non-missing arguments to min, returning InfNot sure why this is happening. If I run the GAMM without the random effect of site, it does not return the error... Not sure why this is happening. If I run the GAMM without the random effect of site, it does not return the error... Many thanks in advance for any help! [[alternative HTML version deleted]]
David Winsemius
2019-Feb-27 01:05 UTC
[R] Help formulating gamm with repeated measures and spatial autocorrelation using mgcv package
Crossposting is explicitly advised against in the rhelp posting guide. Furthermore, this is the wrong list for this sort of question within the r-project hierarchy of mailing lists. I do not believe an answer is possible in the absence of the data (and note the request .... some would say demand... for reproducible code and data at the end of every posting from the Rhelp server). And finally rhelp is a plain text list, so posting with html is also deprecated. Please read the posting guide. I'm just repeating relevant points that are already discussed there at greater length and clarity. David On 2/26/19 2:36 PM, Julie Lee-Yaw via R-help wrote:> (Also posted on StackExchange but submitting to R-help to reach more potential experts)I am using the gamm function in the mgcv package in R to specify a model that predicts abundance with respect to elevation and year based on repeated measures from several sites. My overarching question is how abundance changes over elevation, knowing and accounting for the fact that it also changes over time. GAMM is used because I do not want to restrict the relationship of either elevation or year with abundance to be linear. I expect the data to be spatially autocorrelated within years (sites closer together will have more similar values than sites further apart within each year) and would like to account for this. > > I'm having trouble figuring out the proper full formulation of the GAMM. > > The variables are: 1) abundance (continuous response) 2) elevation (numeric, continuous predictor) 3) year (numeric, continuous predictor as we expect a gradual change in abundance over time) 4) spatial autocorrelation term (based on the lat/long of the sites where data were collected) 5) site (random factor) > > The model formulation I have come up with is: > > model<-gamm(abundance ~ s(elevation, bs = "tp")+s(year, bs = "tp"), correlation=corSpher(form = ~ y+x|year), random=list(site=~1), data=input.data) > > My questions are: > > Is the repeated measures nature of the data adequately accounted for here or do I also need to include year in my random effects (nest site in year)? > > Have I properly taken year into account in my spatial autocorrelation term? > Finally, when running this model, I get an error and a warning:Error in corFactor.corSpatial(object):??Na/NaN/Inf in foreign function call (arg 1)?In addition: Warning message:?In min(unlist(attr(object,"covariate"))):?no non-missing arguments to min, returning InfNot sure why this is happening. If I run the GAMM without the random effect of site, it does not return the error... > > Not sure why this is happening. If I run the GAMM without the random effect of site, it does not return the error... > > Many thanks in advance for any help! > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.