Re: [R] Survreg function for loglogistic hazard estimation

2010-03-19 Thread akeras

I a trying to use survreg to fit a Weibull distribution. From the last few
messages I understand how to interpret the parameters. However, how do I get
the covariance of lambda and alpha? Is there a predict command for that?

Thanks
-- 
View this message in context: 
http://n4.nabble.com/Survreg-function-for-loglogistic-hazard-estimation-tp893503p1604918.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Survreg function for loglogistic hazard estimation

2009-06-08 Thread Terry Therneau

---begin included message --

I am trying to use R to do loglogistic hazard estimation.  My plan is to
generate a loglogistic hazard sample data and then use survreg to estimate
it.  If everything is correct, survreg should return the parameters I have
used to generate the sample data.  

I have written the following code to do a time invariant hazard estimation. 
The output of summary(modloglog) shows the factor loading of dfico is -0.002
instead of 0.005.  Also I can not find the survreg's output of alpha and
beta of loglogistic regression.  Any comments?  Thanks a lot, 

...
-end inclusion --

 The survreg function uses the location-scale parameterizations found in 
Kalbfleisch and Prentice's book The statistical analysis of failure time 
data. 
 Looking at your code, you are using something different
 
  You KP
  1/a lambda
  b   gamma
  
And from KP: lambda = exp(-alpha), gamma= 1/sigma, where
   alpha = linear predictor from the fit
   sigma = scale factor from the fit
I would suggest checking out a copy of the book to verify the above.   
   
 Second, your method of constructing a random time from the distribution is a 
mystery to me.  I believe your code is equivalent to
  y - min(which(runif(n)  constant))
for any given y (with changing values of the constant).
This is a value from the geometic distribution.  

Terry Therneau

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Survreg function for loglogistic hazard estimation

2009-06-08 Thread chenjiakai

Dear Terry,

Thanks a lot for your reply.  The result of survreg reads like: 

Call:
survreg(formula = Surv(end, status) ~ fico_demean, data = raw, 
dist = loglogistic, model = TRUE)
   Value Std. Error  z p
(Intercept)  2.98365   1.34e-03 2233.2  0.00e+00
fico_demean -0.00183   5.36e-05  -34.2 4.18e-256
Log(scale)  -1.41070   2.65e-03 -532.9  0.00e+00

So given your transform the intercept term and log(scale) matches the a and
b respectively - thanks a lot.  The effect of fico_demean, however, still
seems not close.  I will try to find the KP book. 

Yes, the function which(rnos = bhaz * exp(dfico[i]*dficoeff))[1] is
identical with min(which(rnos = bhaz * exp(dfico[i]*dficoeff))), because
the vector of subscription returned by 'which' is always ascending.  bhaz is
not a constant but a vector of baseline hazard rate, so 'which' will do a
element by element comparison.  If bhaz is a constant, then endtime[i] will
follow a geometric distribution. 

I appreciate your help.  Thanks a lot.

Jiakai Chen


Terry Therneau wrote:
 
 
  The survreg function uses the location-scale parameterizations found in 
 Kalbfleisch and Prentice's book The statistical analysis of failure time
 data. 
  Looking at your code, you are using something different
  
   You KP
   1/a lambda
   b   gamma
   
 And from KP: lambda = exp(-alpha), gamma= 1/sigma, where
alpha = linear predictor from the fit
  sigma = scale factor from the fit
 I would suggest checking out a copy of the book to verify the above. 
  
  Second, your method of constructing a random time from the distribution
 is a 
 mystery to me.  I believe your code is equivalent to
   y - min(which(runif(n)  constant))
 for any given y (with changing values of the constant).
 This is a value from the geometic distribution.  
 
 Terry Therneau
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://www.nabble.com/Survreg-function-for-loglogistic-hazard-estimation-tp23907598p23927718.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Survreg function for loglogistic hazard estimation

2009-06-06 Thread chenjiakai

I am trying to use R to do loglogistic hazard estimation.  My plan is to
generate a loglogistic hazard sample data and then use survreg to estimate
it.  If everything is correct, survreg should return the parameters I have
used to generate the sample data.  

I have written the following code to do a time invariant hazard estimation. 
The output of summary(modloglog) shows the factor loading of dfico is -0.002
instead of 0.005.  Also I can not find the survreg's output of alpha and
beta of loglogistic regression.  Any comments?  Thanks a lot, 

Jiakai Chen

Code: 

BEGIN==
# A time invariant loglogistic estimation
library(survival)

# Clear the workspace
rm(list = ls(all = TRUE))

# Totally 100K samples which may die during 100 periods 
timeline = 100 
samplesize = 10


dfico - rnorm(samplesize, mean = 0, sd = 25)
dficoeff - 0.005

# Baseline loglogistic hazard function stored in bhaz
a- 20
b - 4
time - 1:timeline
bhaz - ((b/a) * (time /a) ^ (b-1))/(1+(time/a)^b)

# Event time stored in endtime.  Baseline hazard function is controlled by 
# dfico value with factor loading dficoeff

endtime - numeric(samplesize)
for ( i in 1:samplesize) {
rnos - runif(timeline)
endtime[i] - which(rnos = bhaz * exp(dfico[i]*dficoeff))[1]
}

# Construct data frame
raw - data.frame(end = endtime, status = 1, fico_demean = dfico)

# Adding censorship
for( i in 1:samplesize) {
if(is.na(raw$end[i])) {raw$status[i] - 0} 
}
for( i in 1:samplesize) {
if(is.na(raw$end[i])) {raw$end[i] - timeline }
}

# Output the factory
factory - factor(raw$end)
plot(factory)

# Use survreg to estimate the coefficents of loglogistic distribution
modloglog - survreg(Surv(end, status) ~ fico_demean, data = raw, model =
TRUE, dist = 'loglogistic')

summary(modloglog)
END==
-- 
View this message in context: 
http://www.nabble.com/Survreg-function-for-loglogistic-hazard-estimation-tp23907598p23907598.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.