簡體   English   中英

在邏輯回歸中更改分類預測變量的參考組

[英]Changing reference group for categorical predictor variable in logistic regression

我正在使用具有0-6級別的分類預測變量進行邏輯回歸。 默認情況下,R將0級視為參考組。

如何在不重命名級別的情況下告訴R使用級別3而不是級別0作為參考?

使用C函數定義數據框中的對比。

如果你的數據幀是DF而因子變量是fct ,那么

DF$fct <- C(DF$fct, contr.treatment, base=3)

(未經測試)。

使用Frank Harrell的軟件包(允許許多其他功能)非常容易。
例如,對於名為“df”的數據幀

library(Hmisc) 
library(rms)
dd=datadist(df)
options(datadist='dd')
(m=lrm(y ~ catvar, data=df)) #uses the mode as the reference group
summary(m, catvar=3) #using level=3 as the reference group
summary(m, catvar=0) #using level=0 as the reference group

(並且,一些示例數據本來不錯 - 您總是可以使用dput輸出一個小數據集)

C功能已經提出,還看contrastsrelevel ,並reorder ,等等。

你可以使用relevel函數:dataframe $ x1 < - relevel(datafrmae $ x1,“在這里輸入參考類別”)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM