用mapply预测

时间:2017-12-05 13:52:57

标签: r list mapply

我对r相对较新。我想知道是否可以翻译

preds <- data.frame(predict(fit, testdf[,predictorNames], se.fit = TRUE)[[1]])

其中fit是线性回归模型,testdf是数据框,如下所示:

predfit  <- mapply('predict', lmfit, testlist[,predictorNames])

其中lmfit是线性回归模型列表,长度为3,testlist是长度为1的列表。

我希望用这个来编写一个带有列表的装袋函数,类似于:http://amunategui.github.io/bagging-in-R/

此处为dput(head(test_df))

test_df <- structure(list(crim = c(0.02177, 0.0351, 0.02009, 0.13642, 0.22969, 0.25199), zn = c(82.5, 95, 95, 0, 0, 0), indus = c(2.03, 2.68, 2.68, 10.59, 10.59, 10.59), chas = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor"), nox = c(0.415, 0.4161, 0.4161, 0.489, 0.489, 0.489), rm = c(7.61, 7.853, 8.034, 5.891, 6.326, 5.783), age = c(15.7, 33.2, 31.9, 22.3, 52.5, 72.7 ), dis = c(6.27, 5.118, 5.118, 3.9454, 4.3549, 4.3549), rad = c(2, 4, 4, 4, 4, 4), tax = c(348, 224, 224, 277, 277, 277),ptratio = c(14.7, 14.7, 14.7, 18.6, 18.6, 18.6), b = c(395.38, 392.78, 390.55, 396.9, 394.87, 389.43), lstat = c(3.11, 3.81, 2.88, 10.87, 10.97, 18.06), medv = c(42.3, 48.5, 50, 22.6, 24.4, 22.5)), .Names = c("crim", "zn", "indus", "chas", "nox", "rm", "age", "dis", "rad", "tax", "ptratio", "b", "lstat", "medv"), row.names = c("203", "204", "205", "206", "207", "208"), class = "data.frame") 

0 个答案:

没有答案