为什么R不调平?

时间:2019-02-14 14:57:42

标签: r regression rms

请在下面找到My data "w"

我有w $ WHO的协变量,它具有三个级别:w$WHO==1, w$WHO==2 and w$WHO==3

我想重新调整水平,因此将w $ WHO == 1设置为参考。

我尝试过

w$WHO <- factor(w$WHO)
w$WHO <- relevel(w$WHO, ref=1)

w$WHO <- relevel(w$WHO, ref="1")

我的脚本是

library(rms)
d <- datadist(w)
options(datadist="d")

model <- cph(Surv(rfs,recurrence)~age + WHO,data=w)
summary(model)

如您所见,调整后的模型选择w$WHO==2作为参考。

            Effects              Response : Surv(rfs, recurrence) 

 Factor        Low    High   Diff.  Effect   S.E.     Lower 0.95 Upper 0.95
 age           48.545 68.907 20.362  0.28228 0.093283  0.099454   0.46512  
  Hazard Ratio 48.545 68.907 20.362  1.32620       NA  1.104600   1.59220  
 WHO - 1:2      2.000  1.000     NA -0.56706 0.156850 -0.874490  -0.25963  
  Hazard Ratio  2.000  1.000     NA  0.56719       NA  0.417080   0.77134  
 WHO - 3:2      2.000  3.000     NA  0.69360 0.152910  0.393910   0.99330  
  Hazard Ratio  2.000  3.000     NA  2.00090       NA  1.482800   2.70010  

这是我的数据

My data

w <- structure(list(age = c(54.36164384, 74.91232877, 64.98356164, 
60.56712329, 57.61369863, 45.85205479, 78.47123288, 59.95616438, 
57.4739726, 25.12876712, 56.61917808, 61.10136986, 58.74246575, 
62.56438356, 55.81917808, 30.83013699, 63.11232877, 56.29863014, 
47.96986301, 40.53424658, 49.9890411, 47.75616438, 40.83835616, 
42.02191781, 49.85205479, 55.05479452, 59.33424658, 71.89589041, 
60.30410959, 50.24383562, 41.3260274, 33.4, 73.27945205, 67.45753425
), WHO = c(3L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 3L, 
2L, 3L, 2L, 1L, 2L, 1L, 1L, 2L, 3L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L), recurrence = c(1L, 1L, 1L, 1L, 0L, 1L, 0L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), rfs = c(19.1, 15.33333333, 
49.16666667, 15.6, 57.16666667, 47.63333333, 54, 16.93333333, 
6.7, 102.1, 24.33666667, 127.7666667, 100.6333333, 25.96666667, 
1.233333333, 13.1, 72.16666667, 62, 97.23333333, 199.1, 24.73333333, 
60.46666667, 10.43333333, 31.76666667, 28.96666667, 56.43333333, 
9.533333333, 114.9333333, 114.8666667, 85.06666667, 107.6, 121.2, 
69.56666667, 70.03333333)), .Names = c("age", "WHO", "recurrence", 
"rfs"), class = "data.frame", row.names = 271:304) 

谢谢, 最好。

1 个答案:

答案 0 :(得分:1)

解决方案是

class Weapon:
    def __init__(self, name, damage, **kwargs):
        self.name = name
        self.damage = damage
        # pass on any remaining arguments
        super().__init__(**kwargs)

class Reloadable:    
    def __init__(self, amount, **kwargs):
        self.amount = amount
        # pass on any remaining arguments
        super().__init__(**kwargs)

class Sniper(Weapon, Reloadable):    
    def __init__(self, name, damage, amount, scope_type):
        self.scope_type = scope_type
        super().__init__(name=name, damage=damage, amount=amount)

    def adjust_scope(self):
        print("Adjusting my scope")