已更新,以更具体地解决该问题。我正在使用31x3矩阵。 Dput()输出如下。
通话数据:
x <- Macro[1:31,3:4]
x <- as.matrix(x)
x
y <- Macro[1:31,2:2]
y <- as.matrix(y)
y
指定火车控制:
ctrl2 = trainControl(
method = "cv",
number = 2,
verboseIter = TRUE
)
适合lm:
myfit <- caret::train(y ~ .,
data = x,
method = "lm",
trControl = ctrl2)
下面的代码返回了运行上述代码的错误。知道如何解决吗?
+ Fold1: intercept=TRUE
- Fold1: intercept=TRUE
+ Fold2: intercept=TRUE
- Fold2: intercept=TRUE
Aggregating results
Fitting final model on full training set
Error in data[, all.vars(Terms), drop = FALSE] : subscript out of bounds
投放:
dput(x)
structure(c(0.615707773, 1.243711825, 1.101635544, 1.168158763,
1.217570671, 1.61196623, 1.175834585, 1.212395636, 1.364939572,
1.568682833, 1.492714256, 1.548748565, 1.587380088, 2.500917187,
2.411769733, 2.209745562, 2.181714652, 2.702684603, 2.151281502,
2.311959904, 2.021725337, 2.811498353, 2.25549484, 2.312197702,
2.371454247, 2.929109631, 2.436780195, 2.37055423, 2.2516274,
2.9347511, 2.594177614, 0.00955776, 1.124040765, 1.388953574,
1.442220109, 1.278039696, 1.492471349, 1.241292358, 1.219318408,
1.106157588, 1.425821283, 1.492232414, 1.297264094, 1.290573552,
1.693672926, 1.615503841, 1.416672157, 1.495830759, 1.909516723,
1.578722765, 1.810574654, 1.460086293, 2.063870658, 1.573873402,
1.875213097, 1.822404408, 2.210370183, 2.00485323, 1.737927831,
1.893701997, 2.512806555, 2.286457171), .Dim = c(31L, 2L), .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
"12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
"22", "23", "24", "25", "26", "27", "28", "29", "30", "31"
), c("c1372", "c5244")))
dput(y)
structure(c(1270.13, 1898.063, 1479.839, 1464.988, 1327.572,
1957.292, 1460.983, 1457.527, 1329.201, 2015.304, 1549.553, 1520.144,
1408.813, 2969.499, 2347.697, 2289.456, 2237.209, 3038.233, 2370.037,
2295.203, 2033.545, 2979.778, 2256.155, 2248.855, 2082.9, 2890.8,
2263.7, 2182.23, 2037, 2873.85, 2326.65), .Dim = c(31L, 1L))