Peter, Andy,

The geoR package has the function likfit() that will fit a likelihood-based geostatistical model that can include a trend model as well (the spatial gradient you refer to, if I understand correctly) and can handle the spatial correlation by specifying a general Matern function or particular cases such as gaussian and exponential. The geoR package deals with continuous response variables; I think your diversity response measures are continuous. The package goeRglm is the extension to binary responses (binomial) and to counts (Poisson). Both are well documented.

HTH

Ruben

-----------------------------------------
Rubén H. Roa-Ureta, Ph. D.
AZTI Tecnalia, Txatxarramendi Ugartea z/g,
Sukarrieta, Bizkaia, SPAIN





-----Original Message-----
From: r-sig-ecology-bounces@r-project.org on behalf of Andy Rominger
Sent: Fri 4/22/2011 10:37 PM
To: Peter Francis
Cc: r-sig-ecology@r-project.org
Subject: Re: [R-sig-eco] Detecting spatial gradient whilst accounting for spatial autocorrelation

Hi Peter,

First a question: are your plant communities sampled at unique "points" (say
areas on the order of 50ha) or are they compilations from entire ecoregions?

If the first (unique "points") then you log-transform your diversities you
could probably fit a classical geo statistical model with lat and lon as
covariates, as well as include a variance-covariance matrix with non-zero
off-diagonal entries (i.e. autocorrelation).  You can do this two ways (that
I know of): (1) build a naive model with least squares, extract the
residuals from that and fit a co-variogram (directly related to the
variance-covariance) to those residuals, then re-calculate the coefficients
with GLS. You can do this with package gstat using the variogram and
fit.variogram functions (NOTE: you'll be subjectively fitting a variogram by
the "eyeball" method).  For that and other reasons, this isn't such a great
approach, in my opinion.

OR (2) find both the variance-covariance matrix AND the coefficients in one
step using maximum likelihood.  I don't know of a pre-packaged function to
do this, but basically you'll need to write out the (log) likelihood and
then use optim or something like that maximize it.  To get you started,
we're assuming your data (after log-transformation) come from a multivariate
normal (one "dimension" for every data point) and that multivariate normal
(MVN) has a mean vector that depends on your covariates (lat, lon, temp,
etc) in a linear way; polynomials would be fine (e.g. lat^2 if you expect
more richness at the equator).  The MVN would also have covariances that
depended on the geographic distance between your points, you can see the
documentation ?variogram for some ideas about what kind of covarianve
functions are commonly used.

As if that's not enough, another option (one that
dosen't necessitate log-transforming your diversity data!) would be to use a
hierarchical Bayesian model where, for example, the diversity at any given
site is Poisson (and conditionally independent from other sites), but the
mean of each site comes from a Gaussian process.  The upside is that a
package exists for doing this; it's called geoRglm.

Finally, if you've collected data for all the ecoregions, this is another
problem entirely.  You'll probably want to do a spatial autoregressive model
(of the conditional--CAR--or simultaneous--SAR--variety).  Check out package
spdep for some useful functions, including some to create "neighborhoods"
(i.e. polygons that share a boundary) that are needed for AR models.

Sorry that was such a long tirade, I hope some of it was useful.  You might
also want to hit up the r-sig-geo list for help on spatial statistics.  On a
side note (to justify my long tirade perhaps) your ecological question
sounds pretty cool, I would use an equally "cool"
(sophisticated) statistical method to make sure you get the right answer.

Good luck,
Andy


On Wed, Apr 20, 2011 at 7:25 AM, Peter Francis <peterfrancis@me.com> wrote:

> Dear List
>
> I have a data set which shows high levels of spatial autocorrelation, the
> sampled plant communities are on a global scale and i am looking for
> correlates of different diversity measures (PD,FD).
>
> I have controlled for the spatial autocorrelation using a GLS model where
> the latitude and longitude of each ecoregion was included as a smooth factor
> in all-statistical models using the corExp function.
>
> i.e
>
> exponential <-corExp(form = ~ Longitude + Latitude)
>
> PD_global <- gls(PD~Elevation+Temperature+Species_Richness, correlation =
> exponential)
>
> Now i want to ask the question; how do these diversity measure vary with
> latitude and longitude i.e is their a spatial gradient to PD or FD, i don't
> think i can put in longitude or latitude as a predictor if i am using it as
> a random variable through the corExp function
>
> i.e
>
> PD_global <- gls(PD~Elevation+Temperature+Species_Richness, ALtitude +
> Longitude, correlation = exponential)
>
>
> But i imagine it is something that is often asked?
>
> Any help would be greatly appreciated.
>
> Thanks in advance
>
> Peter
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


	[[alternative HTML version deleted]]

