[R] predict error for survreg with natural splines

Charles C. Berry cberry at tajo.ucsd.edu
Wed Dec 5 01:54:26 CET 2007


On Tue, 4 Dec 2007, Charles C. Berry wrote:

>
>
> I think coxph() leaves safe prediction off by default. You need to turn it 
> on.


Sorry for the misdirection, I see now that you are describing survreg() 
not coxph().

But even coxph() seems to barf on this.

A possible workaround:

> n <- data.frame(age=c(65,rep(mean(ovarian$age)), 10))
> predict(s, newdata=n)[-1]
[1] -0.4182318 -1.9911592
>

Chuck


>
> See
>
> 	?predict.coxph
>
> Chuck
>
> On Wed, 5 Dec 2007, Gad Abraham wrote:
>
>>  Hi,
>>
>>  The following error looks like a bug to me but perhaps someone can shed
>>  light on it:
>> 
>> >  library(splines)
>> >  library(survival)
>> >  s <- survreg(Surv(futime, fustat) ~ ns(age, knots=c(50, 60)),
>>  data=ovarian)
>> >  n <- data.frame(age=rep(mean(ovarian$age), 10))
>> >  predict(s, newdata=n)
>>  Error in qr.default(t(const)) :
>>    NA/NaN/Inf in foreign function call (arg 1)
>>
>>  Thanks,
>>  Gad
>> 
>> 
>> 
>> >  sessionInfo()
>>  R version 2.6.1 (2007-11-26)
>>  i486-pc-linux-gnu
>>
>>  locale:
>>  LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;
>>  LC_COLLATE=en_AU.UTF-8;LC_MONETARY=en_AU.UTF-8;LC_MESSAGES=en_AU.UTF-8;
>>  LC_PAPER=en_AU.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;
>>  LC_MEASUREMENT=en_AU.UTF-8;LC_IDENTIFICATION=C
>>
>>  attached base packages:
>>  [1] splines   stats     graphics  grDevices utils     datasets  methods
>>  [8] base
>>
>>  other attached packages:
>>  [1] survival_2.34
>>
>>  loaded via a namespace (and not attached):
>>  [1] rcompgen_0.1-17
>> 
>> 
>>
>>  --
>>  Gad Abraham
>>  Department of Mathematics and Statistics
>>  The University of Melbourne
>>  Parkville 3010, Victoria, Australia
>>  email: g.abraham at ms.unimelb.edu.au
>>  web: http://www.ms.unimelb.edu.au/~gabraham
>>
>>  ______________________________________________
>>  R-help at 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.
>> 
>
> Charles C. Berry                            (858) 534-2098
>                                            Dept of Family/Preventive 
> Medicine
> E mailto:cberry at tajo.ucsd.edu	            UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
>
>
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list