如何从 R 中的两个栅格计算 r2?
How to compute r2 from two rasters in R?
我有两个栅格,我想查看两者之间的相关性,并获得 r2。
TOTAL2
class : RasterLayer
dimensions : 2803, 5303, 14864309 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 60.85, 105.0417, 15.95833, 39.31667 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : layer
values : 0, 400 (min, max)
> lpjENLF$VegCX2X0.7
class : RasterLayer
dimensions : 2803, 5303, 14864309 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 60.85, 105.0417, 15.95833, 39.31667 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : VegCX2X0.7
values : 1.874989e-05, 350 (min, max)
如何计算这两个栅格之间的 r2 值?我试图将两个栅格转换为数据帧,但两个数据帧 return 都为 NA
。然后我申请 na.rm=T
并尝试找到 r2 但两个栅格的数据帧长度变得不同。我尝试的第二个解决方案是堆叠两个栅格并应用此代码:
layerStats(rasterstack,'pearson')
然而我得到:
$`pearson correlation coefficient`
VegCX2X0.7 layer
VegCX2X0.7 NA NA
layer NA NA
$mean
VegCX2X0.7 layer
NA NA
选项 1:您可以在 layerStats
中使用 na.rm
layerStats(rasterstack, 'pearson', na.rm=T)
选项 2:您可以先从栅格对象中提取值并应用内置函数 cor
。使用此函数,您应该添加参数 use="complete.obs" to get it working with
NA` values.
cor(values(TOTAL2), values(lpjENLF$VegCX2X0.7), use="complete.obs", method = 'pearson')
我有两个栅格,我想查看两者之间的相关性,并获得 r2。
TOTAL2
class : RasterLayer
dimensions : 2803, 5303, 14864309 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 60.85, 105.0417, 15.95833, 39.31667 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : layer
values : 0, 400 (min, max)
> lpjENLF$VegCX2X0.7
class : RasterLayer
dimensions : 2803, 5303, 14864309 (nrow, ncol, ncell)
resolution : 0.008333333, 0.008333333 (x, y)
extent : 60.85, 105.0417, 15.95833, 39.31667 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : VegCX2X0.7
values : 1.874989e-05, 350 (min, max)
如何计算这两个栅格之间的 r2 值?我试图将两个栅格转换为数据帧,但两个数据帧 return 都为 NA
。然后我申请 na.rm=T
并尝试找到 r2 但两个栅格的数据帧长度变得不同。我尝试的第二个解决方案是堆叠两个栅格并应用此代码:
layerStats(rasterstack,'pearson')
然而我得到:
$`pearson correlation coefficient`
VegCX2X0.7 layer
VegCX2X0.7 NA NA
layer NA NA
$mean
VegCX2X0.7 layer
NA NA
选项 1:您可以在 layerStats
na.rm
layerStats(rasterstack, 'pearson', na.rm=T)
选项 2:您可以先从栅格对象中提取值并应用内置函数 cor
。使用此函数,您应该添加参数 use="complete.obs" to get it working with
NA` values.
cor(values(TOTAL2), values(lpjENLF$VegCX2X0.7), use="complete.obs", method = 'pearson')