作者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/m.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