[問題] GLM回歸請教

看板R_Language作者 (工人)時間6年前 (2018/04/06 10:35), 6年前編輯推噓1(104)
留言5則, 3人參與, 6年前最新討論串1/3 (看更多)
[問題類型]: 程式諮詢(我想用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://www.ptt.cc/bbs/R_Language/M.1522982132.A.1A9.html

04/06 10:55, 6年前 , 1F
formula=Classckd~.
04/06 10:55, 1F

04/06 10:55, 6年前 , 2F
我想你是要這個
04/06 10:55, 2F

04/06 10:55, 6年前 , 3F
idx <- c(1, 3, 5) # 假設你只要第1、3跟5個columns
04/06 10:55, 3F
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

04/06 18:28, 6年前 , 4F
推一樓寫法,意思是除了y以外的變數都會自動塞進自變
04/06 18:28, 4F

04/06 18:28, 6年前 , 5F
數去跑回歸
04/06 18:28, 5F
文章代碼(AID): #1Qnjpq6f (R_Language)
文章代碼(AID): #1Qnjpq6f (R_Language)