作者jasonfghx (工人)
看板R_Language
标题[问题] GLM回归请教
时间Fri Apr 6 10:35:29 2018
[问题类型]:
程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来)
[软体熟悉度]:
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
[1] "Age" "Blood Pressure" "Specific
Gravity"
[4] "Albumin" "Sugar" "Red Blood
Cellsabnormal"
[7] "Red Blood Cellsnormal" "Pus Cellabnormal" "Pus
Cellnormal"
[10] "Pus Cell clumpsnotpresent" "Pus Cell clumpspresent"
"Bacterianotpresent"
[13] "Bacteriapresent" "Blood Glucose Random" "Blood Urea"
[16] "Serum Creatinine" "Sodium" "Potassium"
[19] "Hemoglobin" "Packed Cell Volume" "White Blood
Cell Count"
[22] "Red Blood Cell Count" "Hypertensionno"
"Hypertensionyes"
[25] "Diabetes Mellitus yes" "Diabetes Mellitusno" "Diabetes
Mellitusyes"
[28] "Coronary Artery Diseaseno" "Coronary Artery Diseaseyes" "Appetitegood"
[31] "Appetitepoor" "Pedal Edemano" "Pedal
Edemayes"
[34] "Anemiano" "Anemiayes" "Classckd"
[37] "Classnotckd"
这是我全部的变数,我想针对"Classckd" 对其他变数做回归
想请教是否有什麽语法可以比较简洁的去做回归
例如data.glm1 <- glm(formula=Classckd~`Pus Cellabnormal`+Age+`Red Blood
Cellsnormal`,data=data.training,family=binomial(link = "logit"))
我想继续加其他变数进去,但是如果打他的名字感觉会程式码很长
想说有没有办法就只打行的数字就好, 只是我试了几个都编译不过
a<-names(data.training)
像我试着把所有名目存到a ,formula=Classckd~ 在这後面加工好像都是无法判读
求是否有比较好的方法 除了全部贴上外
谢谢
[程式范例]:
[关键字]:
Glm
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 180.217.254.88
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1522982132.A.1A9.html
1F:→ F0011010101: formula=Classckd~. 04/06 10:55
2F:→ clansoda: 我想你是要这个 04/06 10:55
3F:→ clansoda: idx <- c(1, 3, 5) # 假设你只要第1、3跟5个columns 04/06 10:55
Error in parse(text = x, keep.source = FALSE) :
<text>:1:22: unexpected symbol
1: Classkd ~ Age+Blood Pressure
^
不好意思 你知道这样的是什麽讯息
我是这样写的
idx <- c(1,2) #假设你要1、3、5这三个variables
my_formula <-as.formula(paste("Classkd ~ ",
paste(colnames(data.training)[idx], collapse = "+")))
谢谢
※ 编辑: jasonfghx (180.217.254.88), 04/06/2018 15:21:14
4F:推 che122333: 推一楼写法,意思是除了y以外的变数都会自动塞进自变 04/06 18:28
5F:→ che122333: 数去跑回归 04/06 18:28