[R] case weights in coxph (survival)
Nicholas LewinKoh
kohnicho at comp.nus.edu.sg
Tue Sep 18 10:20:22 CEST 2001
Hi,
I am having trouble with the survival library, particualrily the coxph
function.
the following works
coxph(jtree9$cph.call,z,rep(1,dim(z)[1]))
Call:
coxph(formula = jtree9$cph.call, data = z, weights = rep(1, dim(z)[1]))
coef exp(coef) se(coef) z p
SM 0.2574 1.294 0.0786 3.274 1.1e03
Sex 0.1283 0.880 0.1809 0.709 4.8e01
RACE 0.3226 0.724 0.0817 3.950 7.8e05
MHHT:MHDM 0.0524 1.054 0.0574 0.913 3.6e01
FHHT:FHCAD:FHDM 0.0361 1.037 0.0412 0.877 3.8e01
Likelihood ratio test=43.8 on 5 df, p=2.55e08 n= 646
but
> coxph(jtree9$cph.call,z,rep(1,dim(z)[1]))$weights
NULL
while the documentation says that a coxph object should have a weights
element if supplied. Further (what I am really trying to do) if I put this
in a function
optimize.W<function(W,G,Groups,cph.call,z){
n<length(Groups)
grp.wt<rep(0,n)
for(i in 1:length(G)){
ind<Groups == G[i]
grp.wt[ind]<W[i]
}
mod<coxph(cph.call,z,grp.wt,na.action=na.omit,singular.ok=T)
sum(mod$residuals^2)
}
> optimize.W(rep(1,13),unique(jtree9$members[,jtree9$depth]),jtree9$members[,jtree9$depth],
jtree9$cph.call,z)
Error in eval(expr, envir, enclos) : Object "grp.wt" not found
I'm puzzled, is this some sort of environment problem?
Here's my R particulars
> R.Version()
$platform
[1] "i686pclinuxgnu"
$arch
[1] "i686"
$os
[1] "linuxgnu"
$system
[1] "i686, linuxgnu"
$status
[1] ""
$major
[1] "1"
$minor
[1] "3.1"
$year
[1] "2001"
$month
[1] "08"
$day
[1] "31"
$language
[1] "R"
I am also using the most recent version of survival from cran.
Thanks
Nicholas
CH3

N Nicholas LewinKoh
/ \ Dept of Statistics
NC C==O Program in Ecology and Evolutionary Biology
   Iowa State University
   Ames, IA 50011
CH C NCH3 http://www.public.iastate.edu/~nlewin
\ / \ / nlewin at iastate.edu
N C
  Currently
CH3 O Graphics Lab
School of Computing
National University of Singapore
The Real Part of Coffee kohnicho at comp.nus.edu.sg
.......................................
rhelp mailing list  Read http://www.ci.tuwien.ac.at/~hornik/R/RFAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: rhelprequest at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the Rhelp
mailing list