How to add a strata variable in the crr function?

398 views Asked by At

I am trying to test out a Fine and Gray regression and to validate if both the "crr" package and the "survival" package produce the same results. I will then be putting these results into Latex.

The survival results work, but for the crr results I am having a problem inserting a strata variable. Instead of treating the strata variable as a strata, it simply treats it as a factor variable.

Here is my code:

#Create the model matrix
cov1 <- model.matrix(~ factor(marriage_husbandNP2$factor_age)
                     + factor(marriage_husbandNP2$factor_marital)
                     + factor(marriage_husbandNP2$factor_rural)
                     + relevel((factor(marriage_husbandNP2$factor_crime)), ref="Theft and Burglary")
                     + factor(marriage_husbandNP2$factor_religion)
                     + factor(marriage_husbandNP2$factor_time)
                     + strata(marriage_husbandNP2$factor_child)
                     + factor(marriage_husbandNP2$factor_place)
                     + factor(marriage_husbandNP2$factor_town),
                     data = marriage_husbandNP2)[,-1]
#create the model
test_newfine <- crr(marriage_husbandNP2$ftime, marriage_husbandNP2$fstatus, cov1=cov1 , failcode=1, cencode=0,
                     na.action=na.omit)

#Print the summary of the results

summary.crr(test_newfine)

Here is part of the results:

factor(marriage_husbandNP2$factor_age)30-39                                                    -0.08958
factor(marriage_husbandNP2$factor_age)40+                                                      -0.03279
factor(marriage_husbandNP2$factor_marital)Married                                              -0.24707
factor(marriage_husbandNP2$factor_rural)Town                                                    0.06140
factor(marriage_husbandNP2$factor_rural)Port cities                                             0.03485
relevel((factor(marriage_husbandNP2$factor_crime)), ref = "Theft and Burglary")Violent crimes  -0.00408
relevel((factor(marriage_husbandNP2$factor_crime)), ref = "Theft and Burglary")Livestock theft  0.69953
relevel((factor(marriage_husbandNP2$factor_crime)), ref = "Theft and Burglary")Arson            0.18090
relevel((factor(marriage_husbandNP2$factor_crime)), ref = "Theft and Burglary")Against society  0.02449
relevel((factor(marriage_husbandNP2$factor_crime)), ref = "Theft and Burglary")Unknown          0.47567
factor(marriage_husbandNP2$factor_religion)Protestant                                          -0.27935
factor(marriage_husbandNP2$factor_religion)Unknown                                             -0.85640
factor(marriage_husbandNP2$factor_time)1848-1853                                                0.47355
strata(marriage_husbandNP2$factor_child)1+                                                     -0.08371
factor(marriage_husbandNP2$factor_place)Munster                                                -0.07983
factor(marriage_husbandNP2$factor_place)Ulster                                                  0.06396
factor(marriage_husbandNP2$factor_place)Connaught                                               0.03635
factor(marriage_husbandNP2$factor_town)1+                                                      -0.36061

I wish for factor_child to be included as a strata, not as a visible covariate. I have also tested the crrs function from the package "crrSC".

test_newfine <- crrs(marriage_husbandNP2$ftime, marriage_husbandNP2$fstatus, cov1=cov1 ,strata=marriage_husbandNP2$factor_child, ctype=1,
 failcode=1, cencode=0,
                    na.action=na.omit)

Although it does produce the results with the variable hidden properly. For some reason, all the tests for the overall significance of the model don't work. Moreover, although the package states that it will produce an object that is crr type, it does not produce a package of this type.

Here are screenshots of how different these two sets look (first is produced by CRR, Second by CRRS):

Produced by CRR

Produced by CRRS

So what would be the best way to include a strata variable into a fine and gray regression using the CRR logic.

0

There are 0 answers