我有一个数据集162 x 152。我想要做的是使用逐步回归,结合数据集上的交叉验证来创建模型,并测试该模型的准确性。
ID RT (seconds) 76_TI2 114_DECC 120_Lop 212_PCD 236_X3Av
4281 38 4.086 1.2 2.322 0 0.195
4952 40 2.732 0.815 1.837 1.113 0.13
4823 41 4.049 1.153 2.117 2.354 0.094
3840 41 4.049 1.153 2.117 3.838 0.117
3665 42 4.56 1.224 2.128 2.38 0.246
3591 42 2.96 0.909 1.686 0.972 0.138这是我拥有的数据集的一部分。我想要构造一个模型,其中Y变量是RT(秒),而我的所有变量(我的预测器)都是数据集中的其他151个变量。我被告知要使用超精益包,其算法是:-
test <- CV.SuperLearner(Y = Y, X = X, V = 10, SL.library = SL.library,
verbose = TRUE, method = "method.NNLS")问题是我对R还很陌生,我在数据上读取数据和执行其他形式的机器学习算法的主要方法是:-
mydata <- read.csv("filepathway")
fit <- lm(RT..seconds~., data=mydata)那么,如何将RT秒列与我的数据输入分开,以便以X和Y数据的形式输入这些数据呢?意思是:--
mydata <- read.csv("filepathway")
mydata$RT..seconds. = Y #separating my Y response variable
Alltheother151variables = X #separating all of my X predictor variables (all 151 of them)
SL.library <- c("SL.step")
test <- CV.SuperLearner(Y (i.e RT seconds column), X (all the other 151 variables that corresponds to the RT values), V = 10, SL.library = SL.library,
verbose = TRUE, method = "method.NNLS")我希望这一切都有意义。谢谢!
发布于 2013-12-07 14:46:54
如果响应变量位于第一列中,则只需使用:
Y <- mydata[ , 1 ]
X <- mydata[ , -1 ][的第一个参数(行号)是空的,因此保留所有行,第二个参数是1 (第一列)或-1 (除了第一列之外的所有内容)。
如果您的响应变量位于其他地方,则可以使用列名:
Y <- mydata[ , "RT..seconds." ]
X <- mydata[ , setdiff( colnames(mydata), "RT..seconds." ) ]https://stackoverflow.com/questions/20442308
复制相似问题