【问题标题】:Regression residuals and fitted values raster outputs in RR中的回归残差和拟合值栅格输出
【发布时间】:2015-01-12 17:04:08
【问题描述】:

我正在使用 10 个光栅文件计算回归。 我能够获得斜率和 Rsquared 的栅格输出,但在生成残差和拟合值时遇到了一些麻烦。

这是我的脚本:

##########################################
require(raster)
require(rgdal)

#Create list of files
rasters <- list.files(pattern='\\.tif$')


time <- 1:nlayers(rasters)
fun <- function(x) { if (is.na(x[1])){ NA } else { lm(x ~ time)$coefficients[2] }}
slope <- calc(rasters, fun)

time <- 1:nlayers(rasters)
fun <- function(x) { if (is.na(x[1])){ NA } else { lm(x ~ time)$;summary(m)$r.squared }}
Rsquared <- calc(rasters, fun)

time <- 1:nlayers(rasters)
fun <- function(x) { if (is.na(x[1])){ NA } else { lm(x ~ time)$;summary(m)$residuals }}
residuals <- calc(rasters, fun)

time <- 1:nlayers(rasters)
fun <- function(x) { if (is.na(x[1])){ NA } else { lm(x ~ time)$;summary(m)$fitted.values }}
fitted.values <- calc(rasters, fun)
##############################

请问,有人可以帮帮我吗?

非常感谢

吉安卡

【问题讨论】:

  • 请详细描述一下“一些麻烦”是什么。你有错误吗?您没有提供任何意见来解决问题reproducible,所以我们不知道问题是什么。

标签: r regression raster


【解决方案1】:

你需要学习 lm 函数。例如,要获得拟合(预测)值,您可以这样做:

y = runif(10)
x = 1:10
m = lm(y~x)
predict(m)

但不是

summary(m)$fitted.values

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    相关资源
    最近更新 更多