我可以看到这已经差不多完成了,但我是R新手,无法弄清楚。非常多,我有一个回归循环(请不要批评数据挖掘),我需要从每个循环中报告一些事情到一个新的列表/数据框/任何最合适的。这里是我的代码:循环回归提取每个回归
#Required packages
require(lattice)
require(plyr)
ACDn <- "ACDn.csv"
x <- as.matrix(read.csv(ACDn, colClasses = "numeric"))
#To find which columns are which, in order to split up the overall dataset.
which(colnames(X)=="H95.H30")
which(colnames(X)=="H99")
#Here i split all the data into their different types, i.e. LHt = Lidar Heights. Please ignore
#those that are unpopulated, as i am waiting on data to run.
Yall <- x[,c(59:79)] #All "True Variables" - BA, MTH, etc.
Y <- Yall[,10] #Specifies which columnn is the Y variable, BA = 10,
#TopHt = 11, SPH = 12, Vol_live = 13, RecovVol = 14
X <- x[,c(1:58,80:95)] #All Lidar metrics and combinations.
LHt <- X[,c(28:41,59:74)]
LCv <- X[,c()]
LKu <- X[,c()]
LSk <- X[,c()]
L?? <- X[,c()]
#Create List file. I
Optmod1 <-
#Loop Creation, need dataset sizes. The ?? are caused by not knowing the exact sizes
#of the relative datasets yet. Somewhere in here i would like the an entry for EACH model to be
#appended to a data.frame (or list, whatever is most appropriate), which would state the variables
# i.e. 'y', 'i', 'j', 'k', 'l', 'm', and the Adj. R-squared value (which i guess can be extracted
# through using 'summary(mod)$adj.r.squared).
For(i in 1:30) {
For(j in 1:??) {
For(k in 1:??) {
For(l in 1:??){
For(m in 1:??){
mod <- lm(Y ~ LHt[i] + LCv[j] + LKu[k] + LSk[l] + L??[m])
}
}
}
}
}
那么好看多了,以后“国防部”已经跑每一次,我只需要它扔“Y”,“我”,“J”,“K”,“L” ,'米',并调整.R平方(我想通过使用“摘要(mod)$ adj.r.squared”)到可抽取的表中。
对不起,如果有任何这是r-illiterate,我是新来的,并刚才给出了规定的代码,因此我的基本理解是稀疏的。
谢谢你的时间!
P.S.随时提出任何问题 - 我会努力回答他们!
非常感谢您的回复。 我的问题是:当我做第二件事你说(最好的做法)我收到一条错误消息: > LHT_names = lapply(1:30,paste(“LHt [”,i,“]”,sep =“”)) 错误get(as.character(FUN),mode =“function”,envir = envir): 找不到模式'function'的对象'LHt [1]' 我该怎么做? – Schmakk 2013-03-26 06:23:26
对不起,这是一个错字...你需要在'paste'之前插入'function(i)'。看看'lapply',并且在它工作时看看那条线的输出。 – Alex 2013-03-26 06:28:06
Hrmmmm,我到了最后一段代码,并得到一个错误,说'function(x)'后面的“=”是意外的。 – Schmakk 2013-03-26 06:34:36