R Dfmacox和SmoothHr:运行代码中的错误

问题描述 投票:0回答:1

我正在尝试从我的数据集中运行代码以进行统计分析(连续预测变量的危险比曲线的非参数估计)。这是我的数据集的标题:

head (db2)
BMIclass2014 OS60m OS60m_m LnNTproBNP  time
         <dbl> <dbl>   <dbl>      <dbl> <dbl>
1            0     1      34       4.32     3
2            0     1      26       4.52     3
3            0     1       1       4.61     3
4            0     1       4       4.69     3
5            0     1      23       4.80     3
6            0     1       2       4.91     3

这是我要运行的代码:

a <- db2$LnNTproBNP
b <- db2$OS60m
df1 <- dfmacox(data = db2, time = db2$OS60m_m, status = 'b', nl.predictors = c('a'), 
               smoother = 'ns', method = 'AIC')
df1$df
hr1 <- smoothHR(time = 'db2$OS60m_m', status = 'b', 
                formula = ~ns (a, df = df1$df), data = db2)

我收到以下错误:

1]参数'time'中定义的变量不在数据集'data'中]

当我运行代码的第一行时;

2)时间必须是数字或整数类

当我运行第二和第三行时。

r smoothing cubic-spline hazard
1个回答
0
投票

您的代码存在一些问题。如果您可以遵循dfmacox包装文件的smoothHRsmoothHR中给出的示例,将很有帮助。由于我没有您的数据,我只能在这里解释其中的一些内容:

您的第一行:

df1 <- dfmacox(data = db2, time = db2$OS60m_m, status = 'b', nl.predictors = c('a'), 
               smoother = 'ns', method = 'AIC')

您收到错误消息,因为time = db2$OS60m_m不正确。它应该是time = "OS60m_m",例如:

df1 <- dfmacox(data = db2, time = "OS60m_m", status = 'b', nl.predictors = c('a'), 
               smoother = 'ns', method = 'AIC')

您的第二行

hr1 <- smoothHR(time = 'db2$OS60m_m', status = 'b', 
                formula = ~ns (a, df = df1$df), data = db2) 

再次,time = 'db2$OS60m_m'应为time = "OS60m_m"。请注意:我尚未测试您代码的其他组件是否也会引起问题。如果您提供一些数据,则有可能。

© www.soinside.com 2019 - 2024. All rights reserved.