Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wish: multivariate stats command #36

Open
wegmann opened this issue Feb 1, 2018 · 0 comments
Open

wish: multivariate stats command #36

wegmann opened this issue Feb 1, 2018 · 0 comments

Comments

@wegmann
Copy link

wegmann commented Feb 1, 2018

a command for linear regression of x~y1+y2+... raster would be handy and optional output of residuals (maybe optional with piecewise regressions, robust linear regressions etc.). To ease this code snippet:

   library(raster)
   library(RStoolbox)
   
   lsat88 <- brick("p224r63_1988.grd")
   lsat11 <- brick("p224r63_2011.grd")
   
   lsat88.ndvi <- spectralIndices(lsat88, red="B3_sre",nir="B4_sre",indices="ndvi")
   lsat11.ndvi <- spectralIndices(lsat11, red="B3_sre",nir="B4_sre",indices="ndvi")

   lm.lsat <- lm(lsat88.ndvi[]~lsat11.ndvi[], na.action = NULL) # can also be done as multivariate regression: x~y1+y2+y3 with dependent and explanatory variables
   summary(lm.xy)

   Coefficients:
        Estimate Std. Error t value Pr(>|t|)    
   yc.ndvi[]   0.248039   0.001339   185.3   <2e-16
   ...
   Multiple R-squared:  0.1702,	Adjusted R-squared:  0.1702 
   ...
   
   resid.lsat <- raster(lsat88)	
   resid.lsat[] <- lm.lsat$residuals
   plot(resid.lsat,stretch="lin")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant