我对R很天真,如果这是一种愚蠢的做法,那么试图完成一些事情就这么高级道歉。
我试图获得x值与y值的系数和相关性。 X中的值是正在测试共同相关性的标准。
我需要找到myList
中表示的结果的积极或消极相关性/置信度。而不是手动将一列放在Y中我只想迭代它以获得每列的结果。
library(rms)
parameters <- read.csv(file="C:/Users/manjaria/Documents/Lek papers/validation_csv.csv", header=TRUE)
#attach(parameters)
myList <- c("name1","name2","name3","name4","name5")
for (cnt in seq(length(myList))) {
Y<- cbind(myList[cnt])
X<- cbind(age,female,income,employed,traveldays,modesafety,prPoolsize)
XVar <-c("age","female","income","employed","traveldays","modesafety","prPoolsize")
summary (Y)
summary (X)
table(Y)
ddist<- datadist(XVar)
options(datadist = 'ddist')
ologit<- lrm(Y ~ X, data = parameters)
print(ologit)
fitted<- predict(ologit, newdata=parameters, type = "fitted.ind")
colMeans(fitted)
}
我遇到了:
Error in model.frame.default(formula = Y ~ X, data = parameters, na.action = function (frame) :
variable lengths differ (found for 'X')
如果我不循环for循环并使用Y的静态名称
Y<- cbind(name1)
效果很好。