1
rcスプライン予測参照が関数内にあるときに変更するよう強制できません。私は65歳を基準にしたい(yhat = 1、lower = 1、upper = 1)。これは、コードが関数 "分析"の外にある場合には完全に機能します。私はdd $ limitsが参照65(出力を参照)に変わったとしても、関数の内部にあるときには "更新"が行われないと思う。おそらく異なる環境ですか?私は環境などを設定するために何時間も努力しましたが、残念なことに成功しませんでした。どんな助けも高く評価されます!参照値をr内の関数内で制限された3次スプラインに変更
library(Hmisc)
library(survival)
library(rms)
library(cmprsk)
bk.tst <- function(analysis)
{
if (analysis=="test") {
dt<-m
}
outcomes<-c("compos", "acs", "death", "vascdeath", "stroke", "majbleed")
for (i in outcomes) {
fvl<- dt$fvl
age<-dt$age
ndt <- data.frame(age, fvl)
dd<-assign('dd', datadist(ndt), pos=1)
options(datadist='dd')
tm<-paste("tt",i, sep="")
SurvObj <- with(dt, Surv(eval(parse(text=tm)), eval(parse(text=i))==1))
f<-cph(SurvObj ~ fvl*rcs(age,c(60,70,80)), type="Survival", method="exact", x=T, y=T)
print(dd$limits)
dd$limits["Adjust to","age"] <- 65
print(dd$limits)
g <- update(f)
ano<-anova(f)
age.intr.rcsplines<-Predict(g, age=45:85, fvl, ref.zero=TRUE, fun=exp)
print(age.intr.rcsplines[20:22,])
}
}
bk.tst("test")
#the output is:
age fvl
Low:effect 57.01027 0
Adjust to 64.62697 0
High:effect 71.69884 1
Low:prediction 39.48545 0
High:prediction 84.64122 1
Low 35.80287 0
High 92.15606 1
age fvl
Low:effect 57.01027 0
Adjust to 65.00000 0
High:effect 71.69884 1
Low:prediction 39.48545 0
High:prediction 84.64122 1
Low 35.80287 0
High 92.15606 1
age fvl yhat lower upper
20 64 0 0.986740 0.9599284 1.014300
21 65 0 1.008632 0.9929697 1.024541
22 66 0 1.034987 0.9799775 1.093084
# when the code is outside the function analysis, then the output is correct with 65 as a reference. That is what I want to happen also inside the function "analysis":
age fvl
Low:effect 57.01027 0
Adjust to 64.62697 0
High:effect 71.69884 1
Low:prediction 39.48545 0
High:prediction 84.64122 1
Low 35.80287 0
High 92.15606 1
age fvl
Low:effect 57.01027 0
Adjust to 65.00000 0
High:effect 71.69884 1
Low:prediction 39.48545 0
High:prediction 84.64122 1
Low 35.80287 0
High 92.15606 1
age fvl yhat lower upper
20 64 0 0.9782956 0.9369436 1.021473
21 65 0 1.0000000 1.0000000 1.000000
22 66 0 1.0261294 0.9868852 1.066934