Re: [R] Make natural splines constant outside boundary

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Sat, 8 Dec 2007 11:13:13 -0800

On Sat, 8 Dec 2007, Charles C. Berry wrote:

> Gad Abraham <g.abraham <at> ms.unimelb.edu.au> writes:
>
>>
>> Hi,
>>
>> I'm using natural cubic splines from splines::ns() in survival
>> regression (regressing inter-arrival times of patients to a queue on
>> queue size). The queue size fluctuates between 3600 and 3900.
>>
>> I would like to be able to run predict.survreg() for sizes <3600 and
>> >3900 by assuming that the rate for <3600 is the same as for 3600 and
>> that for >4000 it's the same as for 4000 (i.e., keep the splines cubic
>> within the boundaries but make them constant outside the boundaries).
>>
>
> [snip]
>
>> Any suggestions?
>
> Here is one.
>
>> range(ovarian$age)
> [1] 38.8932 74.5041
>> trim <- function(x) pmin(74.5041 ,pmax(38.8932 , x))
>> s <- survreg(Surv(futime, fustat) ~ ns(age, knots=c(50,
> 60),Boundary.knots=c(38.8932, 74.5041)),data=ovarian)
>> s2 <- survreg(Surv(futime, fustat) ~ ns(trim(age), knots=c(50,
> 60),Boundary.knots=c(38.8932, 74.5041)),data=ovarian)

Should have copy-and-pasted this here:

newage <- data.frame( age=seq(10,200,10 ) )

>> matplot(newage, cbind(predict(s,newdata=newage),predict(s2,newdata=newage)))

Sorry 'bout the line wraps and bad formatting.

Chuck

--
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

______________________________________________
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.
Received on Sat 08 Dec 2007 - 19:19:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Dec 2007 - 06:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.