[R] mgcv gam predict problem

2011-03-28 Thread Philip Gautier
Hello

I'm using function gam from package mgcv to fit splines.  When I try
to make a prediction slightly beyond the original 'x' range, I get
this error:

 A = runif(50,1,149)
 B = sqrt(A) + rnorm(50)
 range(A)
[1]   3.289136 145.342961


 fit1 = gam(B ~ s(A, bs=ps), outer.ok=TRUE)
 predict(fit1, newdata=data.frame(A=149.9), outer.ok=TRUE)
Error in splineDesign(knots, x, ord, derivs, outer.ok = outer.ok) :
  the 'x' data must be in the range 3.14708 to 145.485 unless you set
'outer.ok = TRUE'


I've inserted the argument 'outer.ok=TRUE' as you can see, but it
hasn't helped.  How can I obtain this prediction?

Thanks,
Philip Gautier
Dept. of Mathematics and Statistics
American University, Washington, DC

__
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] mgcv gam predict problem

2011-03-28 Thread Vito Muggeo (UniPa)

dear Philip,
I am not able to solve your problem, however the error message you get 
does not depends on mgcv::gam, therefore gam(,..outer.ok=TRUE) or 
predict.gam(,outer.ok=TRUE) do not make sense.


The error message comes from the function splines::splineDesign which is 
called when the option bs=ps is used.


I think the error depends on the fact that you want to predict a value 
outside the observed range of the covariate. When using P-splines the 
predictions outside the range follow a given polynomial..


hope this helps
vito




Il 28/03/2011 7.10, Philip Gautier ha scritto:

Hello

I'm using function gam from package mgcv to fit splines.  When I try
to make a prediction slightly beyond the original 'x' range, I get
this error:


A = runif(50,1,149)
B = sqrt(A) + rnorm(50)
range(A)

[1]   3.289136 145.342961



fit1 = gam(B ~ s(A, bs=ps), outer.ok=TRUE)
predict(fit1, newdata=data.frame(A=149.9), outer.ok=TRUE)

Error in splineDesign(knots, x, ord, derivs, outer.ok = outer.ok) :
   the 'x' data must be in the range 3.14708 to 145.485 unless you set
'outer.ok = TRUE'




I've inserted the argument 'outer.ok=TRUE' as you can see, but it
hasn't helped.  How can I obtain this prediction?

Thanks,
Philip Gautier
Dept. of Mathematics and Statistics
American University, Washington, DC

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



--

Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726/485612
http://dssm.unipa.it/vmuggeo

__
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] mgcv gam predict problem

2011-03-28 Thread Simon Wood
You can get around this by using the 'knots' argument to 'gam' to 
specify p-spline knots which span the range over which you want to 
predict. Alternatively use the cr, tp or ds bases (splines with 
derivative based penalties), which don't have this problem.


best,
Simon

On 28/03/11 06:10, Philip Gautier wrote:

Hello

I'm using function gam from package mgcv to fit splines.  When I try
to make a prediction slightly beyond the original 'x' range, I get
this error:


A = runif(50,1,149)
B = sqrt(A) + rnorm(50)
range(A)

[1]   3.289136 145.342961



fit1 = gam(B ~ s(A, bs=ps), outer.ok=TRUE)
predict(fit1, newdata=data.frame(A=149.9), outer.ok=TRUE)

Error in splineDesign(knots, x, ord, derivs, outer.ok = outer.ok) :
   the 'x' data must be in the range 3.14708 to 145.485 unless you set
'outer.ok = TRUE'




I've inserted the argument 'outer.ok=TRUE' as you can see, but it
hasn't helped.  How can I obtain this prediction?

Thanks,
Philip Gautier
Dept. of Mathematics and Statistics
American University, Washington, DC

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




--
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603   http://people.bath.ac.uk/sw283

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