【发布时间】: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