r语言 - Dfmacox 和 SmoothHr:运行代码中的错误



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

db2 <-structure(list(IBM = c(2, 3, 2, 5, 0, 0, 3, 0, 0, 4, 
0, 2, 0, 5, 2, 0, 2, 5, 4, 3, 3, 0, 2, 0, 0, 5, 0, 2, 0, 4, 3, 
4, 4, 2, 2, 3, 0, 2, 4, 0, 2, 0, 3, 5, 3, 0, 3, 1, 0, 2, 3, 0, 
2, 3, 2, 0, 3, 2, 2, 3, 3, 3, 2, 1, 2, 2, 4, 2, 2, 2, 4, 0, 0, 
0, 2, 2, 3, 2, 2, 3, 3, 0, 2, 0, 0, 5, 3, 2, 2, 2, 0, 3, 3, 2, 
2, 2, 2, 0, 2), 
OS60m = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1), 
OS60m_m = c(32, 22, 58, 44, 34, 26, 12, 1, 4, 7, 23, 
9, 2, 16, 3, 50, 17, 36, 19, 44, 1, 0, 4, 35, 45, 25, 57, 8, 
11, 1, 13, 30, 38, 59, 21, 32, 35, 21, 10, 57, 0, 39, 0, 30, 
33, 17, 55, 51, 27, 13, 15, 8, 35, 6, 2, 27, 55, 37, 12, 18, 
13, 47, 20, 43, 29, 19, 25, 34, 20, 13, 17, 16, 37, 45, 57, 25, 
20, 45, 29, 28, 22, 33, 2, 45, 16, 38, 35, 11, 58, 40, 6, 4, 
47, 27, 45, 39, 34, 2, 56), 
LnNTproBNP = c(3.58, 3.78, 3.99, 
4.22, 4.32, 4.52, 4.54, 4.61, 4.69, 4.75, 4.8, 4.88, 4.91, 4.93, 
4.94, 4.96, 4.98, 4.98, 5.06, 5.09, 5.19, 5.23, 5.23, 5.26, 5.29, 
5.29, 5.3, 5.32, 5.33, 5.41, 5.42, 5.42, 5.45, 5.47, 5.48, 5.49, 
5.5, 5.52, 5.52, 5.52, 5.53, 5.55, 5.59, 5.6, 5.61, 5.62, 5.64, 
5.65, 5.65, 5.67, 5.7, 5.71, 5.71, 5.71, 5.73, 5.74, 5.75, 5.78, 
5.79, 5.79, 5.8, 5.81, 5.81, 5.82, 5.83, 5.84, 5.84, 5.84, 5.85, 
5.86, 5.86, 5.86, 5.91, 5.91, 5.92, 5.94, 5.94, 5.95, 5.96, 5.96, 
5.97, 5.98, 5.99, 6, 6.02, 6.02, 6.03, 6.06, 6.06, 6.08, 6.08, 
6.09, 6.1, 6.11, 6.11, 6.12, 6.13, 6.15, 6.15)), 
row.names = c(NA,-99L), class = c("tbl_df", "tbl", "data.frame"))

这是我尝试运行的代码:

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(参数"时间"中定义的变量不在数据集"数据"中

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

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

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

Edit

我已经为您的问题添加了数据。由于您从Excel导入数据,因此需要将其更改为data.framesmoothHR因为默认值(包括tbl_dftbl(可能无法很好地工作。

db2<-data.frame(db2)
db2$a <- db2$LnNTproBNP
db2$b <- db2$OS60m
df1 <- dfmacox(time = "OS60m_m", status = "b", nl.predictors = c('a'), 
smoother = 'ns', method = 'AIC', data=db2)
df1
$df
[1] 2
$AIC
[1] 720.0194
$AICc
[1] 722.272
$BIC
[1] 725.2096
$myfit
Call:
coxph(formula = covar, data = data, x = TRUE)
coef exp(coef) se(coef)      z     p
ns(a, df = 2)1  0.8969    2.4519   1.0972  0.817 0.414
ns(a, df = 2)2 -0.4574    0.6329   0.3684 -1.242 0.214
Likelihood ratio test=2.25  on 2 df, p=0.3248
n= 99, number of events= 99 
$method
[1] "AIC"
$nl.predictors
[1] "a"

相关内容

  • 没有找到相关文章

最新更新