Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 210598

How to add a strata variable in the crr function?

$
0
0

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 matrixcov1 <- 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 modeltest_newfine <- crr(marriage_husbandNP2$ftime, marriage_husbandNP2$fstatus, cov1=cov1 , failcode=1, cencode=0,                     na.action=na.omit)#Print the summary of the resultssummary.crr(test_newfine)

Here is part of the results:

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


Viewing all articles
Browse latest Browse all 210598

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>