[R-sig-Geo] (no subject)

Roger Bivand Roger.Bivand at nhh.no
Mon Apr 3 17:31:50 CEST 2017


On Mon, 3 Apr 2017, Patrick Schwager wrote:

> Dear list,
>
> I am currently working on modelling species distribution and try to account
> spatial autocorrelation. I use R and I successfully managed to incorporate
> moran's eigenvectors as predictor to my species distribution model using
> GLM (logit). I followed Dormann et al. (2007
> <https://www2.unil.ch/biomapper/Download/Dormann-EcoGra-2007.pdf>) and the
> appendix
> <http://www.ecography.org/sites/ecography.org/files/appendix/e5171.pdf>. I
> think I got corrected statistics in the moran.test() of model residuals as
> the p-value increases. Also the AIC score indicates a better spatial model.
>

Please post text-only messages: posting HTML has severely modified your 
code and output.

Please provide a reproducible example, preferably from built-in data.

Please state clearly where evaluate() and predict() are coming from. I 
think predict is stats::predict, but evaluate is from which package? 
dismo?

Most likely they expect the ME fitted matrix is not being found in the 
scope of newdata. Note that out of sample prediction for SF/ME models is 
not defined, as the weights are not the same, so the eigenvectors will not 
be either.

Hope this clarifies,

Roger

>
> *Normal model glm:*
>
> Moran I test under randomisation
>
>
>
> data:  residuals(model)
>
> weights: priclus.listw
>
>
>
> Moran I statistic standard deviate = 7.5632, p-value = 1.966e-14
>
> alternative hypothesis: greater
>
> sample estimates:
>
> Moran I statistic       Expectation          Variance
>
>      0.264335666      -0.007633588       0.001293086
>
>
>
> *Spatial model:*
>
> Moran I test under randomisation
>
>
>
> data:  residuals(model)
>
> weights: priclus.listw
>
>
>
> Moran I statistic standard deviate = 1.5572, p-value = 0.05972
>
> alternative hypothesis: greater
>
> sample estimates:
>
> Moran I statistic       Expectation          Variance
>
>      0.045968614      -0.007633588       0.001184932
>
>
>
> *See the summary for both models below:*
>
>> summary(priclus8<- glm(pb_train ~ gesteine + schnee_tag_1 + rs_hospso, family= binomial(link="logit"), data=envtrain))
>
>
>
>        Call:
>
>        glm(formula = pb_train ~ gesteine + schnee_tag_1 + rs_hospso,
>
>            family = binomial(link = "logit"), data = envtrain)
>
>
>
>        Deviance Residuals:
>
>             Min        1Q    Median        3Q       Max
>
>        -2.76552  -0.18741  -0.00449   0.34032   2.03205
>
>
>
>        Coefficients:
>
>                     Estimate Std. Error z value Pr(>|z|)
>
>        (Intercept)  75.89890   20.21051   3.755 0.000173 ***
>
>        gesteine1     2.05287    0.55421   3.704 0.000212 ***
>
>        schnee_tag_1 -0.03328    0.01685  -1.975 0.048223 *
>
>        rs_hospso    -1.56444    0.37856  -4.133 3.59e-05 ***
>
>        ---
>
>        Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
>
>
>        (Dispersion parameter for binomial family taken to be 1)
>
>
>
>            Null deviance: 387.96  on 284  degrees of freedom
>
>        Residual deviance: 129.56  on 281  degrees of freedom
>
>        AIC: 137.56
>
>        Number of Fisher Scoring iterations: 7
>
>
>
>> sevm1 <- fitted(ME(pb_train ~ gesteine + schnee_tag_1 + rs_hospso, data=envtrain, family= binomial(link="logit"),listw=ME.listw))
>
>> summary(priclus8_mem<- glm(pb_train ~ gesteine + schnee_tag_1 + rs_hospso+ I(sevm1), family= binomial(link="logit"), data=envtrain) )
>
>
>
>    Call:
>
>    glm(formula = pb_train ~ gesteine + schnee_tag_1 + rs_hospso +
>
>        I(sevm1), family = binomial(link = "logit"), data = envtrain)
>
>
>
>    Deviance Residuals:
>
>        Min       1Q   Median       3Q      Max
>
>    -3.6095  -0.1415  -0.0025   0.0784   2.5099
>
>
>
>    Coefficients:
>
>                   Estimate Std. Error z value Pr(>|z|)
>
>    (Intercept)   102.50545   28.27283   3.626 0.000288 ***
>
>    gesteine1       0.80346    0.79373   1.012 0.311417
>
>    schnee_tag_1   -0.06435    0.02448  -2.628 0.008586 **
>
>    rs_hospso      -1.99483    0.52879  -3.772 0.000162 ***
>
>    I(sevm1)vec8   35.86461    8.38806   4.276 1.91e-05 ***
>
>    I(sevm1)vec25 -46.33209    8.82448  -5.250 1.52e-07 ***
>
>    ---
>
>    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
>
>
>    (Dispersion parameter for binomial family taken to be 1)
>
>
>
>        Null deviance: 387.959  on 284  degrees of freedom
>
>    Residual deviance:  69.198  on 279  degrees of freedom
>
>    AIC: 81.198
>
>
>
>    Number of Fisher Scoring iterations: 8
>
>
>
> Now I would like to compare the results of evaluate() and the
> predictions between the normal model and the spatial model.
> For the spatial model I get an error: "there are different length for
> the variables".
> I also want to plot the SAC-corrected predicted model to visualize the
> distribution.
>
>> e.priclus8_mem<-evaluate(test_pres_val, test_abs_val, priclus8_mem)
>
>
>
> #Error in model.frame.default(Terms, newdata, na.action = na.action,
>
> #xlev = object$xlevels) :  Variablenlängen sind unterschiedlich
>
> #(gefunden für 'I(sevm1)') In addition: Warning message:'newdata' had
>
> #120 rows but variables found have 285 rows
>
>
>
>> plot(pclus8_mem<-predict(env_data, priclus8_mem, type="response"), main="GML priclu8_mem")
>
>
>
> #Error in model.frame.default(Terms, newdata, na.action = na.action,
>
> #xlev = object$xlevels):Variablenlängen sind unterschiedlich (gefunden
>
> #für 'I(sevm1)')
>
>
>
> Is this error caused by points with no neighbour? I used zero.polycy=TRUE
> to accept no neighbours in the nb object. What else could be the problem?
>
> I also read Bivand et al. (2008): Applied Spatial Data Analysis with R and
> Borcard et al. (2011): Numerical Ecology with R. The given examples always
> refer to vector data but I am working with raster data…
>
> I am new in the matter and cannot get any further here. I have certainly
> overlooked something or misunderstood. Any help and further reading is
> appreciated!
>
> Many thanks,
>
> Patrick
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no
Editor-in-Chief of The R Journal, https://journal.r-project.org/index.html
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en


More information about the R-sig-Geo mailing list