I would like to use the P
value of cox.zph
in a Sweave document, something like this:
<<echo=FALSE,results=tex>>=
campo = campos[1]
m1=coxph(Surv(TimeVar,EventVar)~Factor)
z=cox.zph(m1)
….
@
If I assign to an object print(cox.zph(m1))
:
temp = print(cox.zph(m1))
I have the p value in the third component temp[3]
, but the instruction print(z)
outputs the results to the document, and I want only to store the P
value in another variable, not to show the results.
I tried invisible function, but it doesn’t work for me.
To answer your specific question, use results=hide
in your list of options.
<<echo=FALSE,results=hide>>=
campo = campos[1]
m1=coxph(Surv(TimeVar,EventVar)~Factor)
z=cox.zph(m1)
temp = print(x)
@
You can then access the temp
variable. A better solution is to pull out the parts of the z
object you need. So in your case, this would be:
##z is a list
z1 = z[[1]]
The variable z1
is a matrix that contains the information you need.