我正在尝试使用 R 中的 gstat 包通过添加的协变量进行一些预测。
我通过以下方式生成 gstat 对象 g:
# We use the prediction sample for pm2.5 (primary) and pm10 (secondary) variable
g <- gstat(NULL, "ln.pm2.5", log(pm25.obs) ~ log(pd$pm25.LE), pd)
# Append the other variables to g
g <- gstat(g, "ln.pm10", log(pm10.obs) ~ log(ndpm10$pm10.LE), ndpm10)
v <- variogram(g)
# Check the output and plot the result
v
plot(v)
# Define the initial variogram model and append it to g
g <- gstat(g, model=vgm(0.04, "Sph", 600, 0.1), fill.all=TRUE)
#g <- gstat(g, model=vgm(0.10, "Sph", 200, 0.03), fill.all=TRUE)# for region B
# Use the LMC for fitting
g.fit <- fit.lmc(v, g)
g.fit
plot(v, g.fit)
所以 g 对象看起来像这样:
> g
data:
ln.pm2.5 : formula = log(pm25.obs)`~`log(pd$pm25.LE) ; data dim = 218 x 10
ln.pm10 : formula = log(pm10.obs)`~`log(ndpm10$pm10.LE) ; data dim = 958 x 10
variograms:
model psill range
ln.pm2.5[1] Nug 0.06798841 0
ln.pm2.5[2] Sph 0.10237623 600
ln.pm10[1] Nug 0.10325992 0
ln.pm10[2] Sph 0.06879960 600
ln.pm2.5.ln.pm10[1] Nug 0.08378829 0
ln.pm2.5.ln.pm10[2] Sph 0.08392523 600
如果我尝试使用这个 g 对象进行预测,我会收到以下错误:
> > tmp1 <- predict.gstat(g, newdata=R1.ctm.data) Error in gstat.formula.predict(d$formula, newdata, na.action = na.action, :
> NROW(locs) != NROW(X): this should not occur In addition: Warning
> messages: 1: 'newdata' had 2220 rows but variables found have 218 rows
> 2: 'newdata' had 2220 rows but variables found have 218 rows
其中 R1.ctm.data 具有以下结构:一个 2220 观测 SpatialPoints DataFrame,具有北距、东距以及 pm2.5 和 pm10(协变量)信息。如果我删除协变量,我没有问题。
谢谢你的帮助