[R-sig-ME] Repeated Observations Linear Mixed Model with Outside-Group Spatial Correlation
Michael Hyland
mhyland at u.northwestern.edu
Tue Mar 21 22:19:05 CET 2017
Thanks for the quick response.
This is a subset. Full dataset is 12,266 observations across 530 groups (or
Bikeshare stations).
for
model_spatial.gau <- update(model_spatial, correlation = corGaus(form = ~
latitude +longitude ), method = "ML")
and
model_spatial.gau <- update(model_spatial, correlation = corGaus(form = ~
latitude +longitude| id ), method = "ML")
the error is "cannot have zero distances in "corSpatial" which I assume is
due to the repeated observations having the same exact lat and lon;
therefore zero distance
Moreover, when I do anything with '| id' I think the model only accounts
for 'within-group' correlations, not across stations
On Tue, Mar 21, 2017 at 4:12 PM, Ben Bolker <bbolker at gmail.com> wrote:
> Your approach seems about right.
>
> - What precisely does "unsuccessful" mean? warnings, errors,
> ridiculous answers?
> - Is this your whole data set or a subset?
> - centering and scaling predictors is always worth a shot to fix
> numeric problems
> - INLA is more powerful than lme for fitting spatial correlations,
> although it's a *steep* learning curve ...
>
>
> On Tue, Mar 21, 2017 at 5:08 PM, Michael Hyland
> <mhyland at u.northwestern.edu> wrote:
> > Hi,
> >
> > I'm new to the listserv.
> >
> > A shortened version of my dataset is below. I am developing a model to
> > forecast monthly ridership at Bikeshare stations. I want to predict
> 'Cnts'
> > as a function of 'Population' - 'Temperature'. The dataset is unbalanced
> > (unequal number of observations for each station) and most of covariates
> do
> > not vary over time, but a few do.
> >
> > I have successfully used lmer() and lme() in R to capture the dependency
> > between the error terms for repeated observations from a given station
> > ('id').
> >
> > model_spatial = lme(log(counts) ~ log(Population)
> > +Drive +Med_Income + Buff2 +Rain + Temperature
> > , data = Data, random = ~1|id, method = "ML" )
> >
> > model_All = lmer(log(counts) ~ log(Population)
> > +Drive +Med_Income + Buff2 +Rain + Temperature
> > + (1|id)
> > , data = Data )
> >
> > However, a Moran's I test of the residuals suggests that the residuals
> are
> > spatially correlated.
> > station.dists <- as.matrix(dist(cbind(Data$longitude, Data$latitude)))
> > station.dists.inv <- 1/station.dists
> > station.dists.inv[is.infinite(station.dists.inv)] <- 0 #Distance
> value is
> > inf for repeated observations from the same station
> > Data$resid_all = resid(model_spatial)
> > Moran.I(Data$resid_all, station.dists.inv)
> >
> >
> > Hence, I need to develop a model in R that accounts for spatial
> correlation
> > across stations, while simultaneously capturing correlations between
> > observations from a single station. I've tried the following updates to
> > the lme() model, but have been unsuccessful.
> > model_spatial.gau <- update(model_spatial, correlation = corGaus(form = ~
> > latitude +longitude ), method = "ML")
> > model_spatial.gau <- update(model_spatial, correlation = corGaus(form = ~
> > latitude +longitude| id ), method = "ML")
> >
> > Is there a way to formulate the correlation matrix in lme() or lmer()
> such
> > that the correlation between repeated obvservations of a given station
> *and*
> > the spatial autocorrelation between stations is accounted for?
> >
> >
> > year month id Cnts latitude longitude Population Drive Med_Income Buff2
> Rain
> > Temperature
> > 2015 8 2 2597 41.87264 -87.62398 4256 0.3418054 76857 127 0.07 71.8
> > 2015 9 2 2772 41.87264 -87.62398 4256 0.3418054 76857 128 0.15 69
> > 2015 10 2 684 41.87264 -87.62398 4256 0.3418054 76857 128 0.07 54.7
> > 2015 11 2 394 41.87264 -87.62398 4256 0.3418054 76857 128 0.15 44.6
> > 2015 12 2 148 41.87264 -87.62398 4256 0.3418054 76857 129 0.16 39
> > 2016 1 2 44 41.87264 -87.62398 4256 0.3418054 76857 129 0.03 24.7
> > 2015 5 3 2303 41.86723 -87.61536 16735 0.4312349 75227 90 0.15 60.4
> > 2015 6 3 3323 41.86723 -87.61536 16735 0.4312349 75227 98 0.24 67.4
> > 2015 7 3 5920 41.86723 -87.61536 16735 0.4312349 75227 98 0.09 72.3
> > 2015 8 3 4405 41.86723 -87.61536 16735 0.4312349 75227 98 0.07 71.8
> > 2015 9 3 3638 41.86723 -87.61536 16735 0.4312349 75227 99 0.15 69
> > 2015 10 3 2061 41.86723 -87.61536 16735 0.4312349 75227 99 0.07 54.7
> > 2015 11 3 1074 41.86723 -87.61536 16735 0.4312349 75227 99 0.15 44.6
> > 2015 12 3 374 41.86723 -87.61536 16735 0.4312349 75227 100 0.16 39
> > 2016 1 3 188 41.86723 -87.61536 16735 0.4312349 75227 100 0.03 24.7
> > 2016 2 3 474 41.86723 -87.61536 16735 0.4312349 75227 100 0.04 30.4
> > 2015 6 4 2968 41.85627 -87.61335 16735 0.4312349 75227 68 0.24 67.4
> > 2015 7 4 4266 41.85627 -87.61335 16735 0.4312349 75227 68 0.09 72.3
> > 2015 8 4 3442 41.85627 -87.61335 16735 0.4312349 75227 68 0.07 71.8
> > 2015 9 4 2552 41.85627 -87.61335 16735 0.4312349 75227 69 0.15 69
> > 2015 10 4 1301 41.85627 -87.61335 16735 0.4312349 75227 69 0.07 54.7
> >
> >
> > Thanks,
> > Mike Hyland
> >
> > [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-mixed-models at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list