# [R] Competing Risks Regression with qualitative predictor with more than 2 categories

Sun Aug 2 16:43:59 CEST 2009

```Hi,

You can use `model.matrix' to create the apropriate design matrix for factor variables.

set.seed(10)

ftime <- rexp(200)

fstatus <- sample(0:2,200,replace=TRUE)

gg <- factor(sample(1:3,200,replace=TRUE),1:3, c('a','b','c'))

cov <- matrix(runif(600),nrow=200)

dimnames(cov)[] <- c('x1','x2','x3')

cov2 = model.matrix( ~ cov + gg)

print(z <- crr(ftime,fstatus,cov2[, -1]))  # you shouldn't have intercept in the FG model

Hope this helps,
Ravi.

____________________________________________________________________

Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619

----- Original Message -----
From: kende jan <kendejan at yahoo.fr>
Date: Sunday, August 2, 2009 6:01 am
Subject: [R] Competing Risks Regression with qualitative predictor with more than 2 categories
To: r-help at r-project.org

> Hello,
>  I have a question regarding competing risk regression using cmprsk
> package (function crr()). I am using R2.9.1. How can I do to assess
> the effect of qualitative predictor (gg) with more than two categories
> (a,b,c) categorie c is the reference category. See above results, gg
[[elided Yahoo spam]]
>  Thank you for your help
>  Jan
>
>  > # simulated data to test
>  > set.seed(10)
>  > ftime <- rexp(200)
>  > fstatus <- sample(0:2,200,replace=TRUE)
>  > gg <- factor(sample(1:3,200,replace=TRUE),1:3,c('a','b','c'))
>  > cov <- matrix(runif(600),nrow=200)
>  > dimnames(cov)[] <- c('x1','x2','x3')
>  > cov2=cbind(cov,gg)
>  > print(z <- crr(ftime,fstatus,cov2))
>
>  convergence:  TRUE
>  coefficients:
>       x1      x2      x3      gg
>   0.2624  0.6515 -0.8745 -0.1144
>  standard errors:
>   0.3839 0.3964 0.4559 0.1452
>  two-sided p-values:
>     x1    x2    x3    gg
>  0.490 0.100 0.055 0.430
>  > summary(z)
>  Competing Risks Regression
>
>  Call:
>  crr(ftime = ftime, fstatus = fstatus, cov1 = cov2)
>
>       coef exp(coef) se(coef)      z p-value
>  x1  0.262     1.300    0.384  0.683   0.490
>  x2  0.652     1.918    0.396  1.643   0.100
>  x3 -0.874     0.417    0.456 -1.918   0.055
>  gg -0.114     0.892    0.145 -0.788   0.430
>
>
>
>  	[[alternative HTML version deleted]]
>
>  ______________________________________________
>  R-help at r-project.org mailing list
>