我正在尝试使用forecast
命令为glm(probit回归)模型生成一个简单的单周期预测。但是在运行以下代码时,我收到以下消息:Error in as.data.frame(newdata) : argument "newdata" is missing, with no default
#generate dataset with unknown value for last period dependent variable
data.set <- data.frame(date= seq(as.Date('2015-01-01'), by = 'days' , length = 100),
replicate(100, sample(0:1,1)), runif(1e2),runif(1e2),runif(1e2))
colnames(data.set) <- c("date", "dv", "iv1", "iv2", "iv3")
data.set.ts <- xts(data.set[-1], order.by=data.set$date)
rm(data.set)
data.set.ts$dv[100] <- NA
#run glm probit model
PRmodel <- glm(dv ~ iv1 + iv2 + iv3, data = data.set.ts[-nrow(data.set.ts),],
family = binomial(link = "probit"))
#generate forecast for last period dv
iv_input <- xts(data.set.ts[, which(colnames(data.set.ts) %in% c("iv1" , "iv2" , "iv3"))],
order.by = index(data.set.ts))
start.date <- index(data.set.ts)[length(index(data.set.ts))]
fcastFn_output <- forecast(PRmodel, xreg=window(iv_input, start = start.date))
我也尝试使用predict
命令,但如果实际缺失,R似乎不会为观察生成预测值。