[R] Use of survreg.distributions

COREY SPARKS corey.sparks at UTSA.EDU
Sat Apr 26 22:15:09 CEST 2008

It would seem to me that your problem is in your data.  For survreg, you have to have positive durations, and if your data have y>=-5 as seen in

>Error in survreg(Surv(y, y >= -5, type = "left") ~ x +  :
>  Invalid survival times for this distribution
>In addition: Warning messages:
>1: In log(dlist$dtrans(Y[exactsurv, 1])) : NaNs produced
>2: In log(y) : NaNs produced

then you have negative durations in the data.  I would suggest truncating your data at y>0, as that would avoid taking natural logs of negative numbers.

Corey Sparks

Corey S. Sparks, Ph.D.

Assistant Professor 
Department of Demography and Organization Studies
University of Texas San Antonio
One UTSA Circle 
San Antonio, TX 78249
email:corey.sparks at utsa.edu

Date: Fri, 25 Apr 2008 10:02:21 -0700 (PDT)
From: Abdus Sattar <upsattar at yahoo.com>
Subject: Re: [R] Use of survreg.distributions
To: Terry Therneau <therneau at mayo.edu>
Cc: r-help at R-project.org
Message-ID: <920678.32263.qm at web58104.mail.re3.yahoo.com>
Content-Type: text/plain

Hello Dr. Therneau:
Thank you for your response. Let me explain to you want I want. My y variable(time) is normal and would like to fit the model on logarithmic transformation of y (log(y)). I tried to run codes according to your suggestion:
tfit=survreg(Surv(y, y>=-5, type="left")~x + cluster(id), dist="lognormal", data=y.data, scale=0, weights=w)

The following error message is giving:
Error in survreg(Surv(y, y >= -5, type = "left") ~ x +  :
  Invalid survival times for this distribution
In addition: Warning messages:
1: In log(dlist$dtrans(Y[exactsurv, 1])) : NaNs produced
2: In log(y) : NaNs produced

Note, the data file y.data does not contain any missing data! Do you know why it is giving me such an error message please?
Thank you again for your helpful comment/suggestion.
Best Regards,
Abdus Sattar
upsattar at yahoo.com

----- Original Message ----
From: Terry Therneau <therneau at mayo.edu>
To: upsattar at yahoo.com
Cc: r-help at R-project.org
Sent: Friday, April 25, 2008 8:46:45 AM
Subject: Re: [R] Use of survreg.distributions

--begin included message ---

I am using survreg(Surv()) for fitting a Tobit model of left-censored
longitudinal data. For logarithmic transformation of y data, I am trying use
survreg.distributions in the following way:
tfit=survreg(Surv(y, y>=-5, type="left")~x + cluster(id), dist="gaussian",
data=y.data, scale=0, weights=w)
tfit=survreg(Surv(y, y>=-5, type="left")~x + cluster(id), dist=my.gaussian,
data=y.data, scale=0, weights=w)

If I run these codes then I got the following error message,

Error in survreg(Surv(y, y >= -5, type = "left") ~ x +  :
Invalid distribution object

Does anybody can help me in identifying the error(s) in these code please?

--- end include ----

  Can you tell us what you are trying to do? 
  Your first model was a fit of y ~ x + eps, eps ~ Gaussian.  If what you want
is log(y) ~ x + eps, then all that you need do is use dist="loggaussian" in the
survreg call.  (Or 'lognormal'; which is the same distribution.)
      Terry Therneau

More information about the R-help mailing list