[R] Do YOU know an equation for splines (ns)?
William Dunlap
wdunlap at tibco.com
Wed Jun 6 22:48:31 CEST 2012
Do you have to include the grouping variable, plotF, in your newdata
argument? E.g., after fitting the model with
rcn10G<-groupedData(N ~ day | plotF, data=rcn10)
fit10 <- lme( N~ns(day, 3), data = rcn10G)
try checking the predictions when you've include plotF in newdata:
par(mfrow=c(2,1))
plot(N ~ day, subset=plotF=="12", data=rcn10G)
points(num, predict(fit10, data.frame(day=num, plotF=rep("12", length(num)))), pch=".", col="red")
plot(N ~ day, subset=plotF=="43", data=rcn10G)
points(num, predict(fit10, data.frame(day=num, plotF=rep("43", length(num)))), pch=".", col="red")
I am no expert on the lme and groupedData, but the general rule is that all variables involved
in the model, except the response, must be given to predict.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Ranae
> Sent: Wednesday, June 06, 2012 10:39 AM
> To: r-help at r-project.org
> Subject: Re: [R] Do YOU know an equation for splines (ns)?
>
> I have not been able to get "predict" (or most functions) to run well with
> grouped data in nlme. I may not have it coded right, but this is what it
> looks like:
>
> http://r.789695.n4.nabble.com/file/n4632567/spline.txt spline.txt
>
> library(nlme)
> library(splines)
>
> rootCN<-read.table("spline.txt", header=TRUE)
> rootCN$plotF<-as.factor(rootCN$plot)
>
> rcn10G<-groupedData(N ~ day | plotF, data=rcn10)
>
> fit10 <- lme( N~ns(day, 3), data = rcn10G)
>
> plot(augPred(fit10))
>
> num<- seq(88,300, len=200)
> lines(num, predict(fit10, data.frame(day=num)))
>
> -Ranae
>
>
> Does
> ?predict.ns
> not do what you want without having to explicitly manipulate the spline
> basis?
>
> -- Bert
>
> On Tue, Jun 5, 2012 at 1:56 PM, Ranae <[hidden email]> wrote:
>
> > Hi,
> >
> > I am looking at the change in N concentration in plant roots over 4 time
> > points and I have fit a spline to the data using ns and lme:
> >
> > fit10 <- lme( N~ns(day, 3), data = rcn10G)
> >
> > I may want to adjust the model a little bit, but for now, let's assume
> > it's
> > good. I get output for the fixed effects:
> >
> > Fixed: N ~ ns(day, 3)
> > (Intercept) ns(day, 3)1 ns(day, 3)2 ns(day, 3)3
> > 1.15676524 0.14509171 0.04459627 0.09334428
> >
> > and coefficients for each experimental unit in my experiment:
> >
> > (Intercept) ns(day, 3)1 ns(day, 3)2 ns(day, 3)3
> > 24 1.050360 -0.42666159 -0.56290877 -0.10714407
> > 13 1.104464 -0.30825350 -0.53311653 -0.05558150
> > 31 1.147878 -0.14548512 -0.78673906 -0.07231781
> > 46 1.177781 -0.22278380 -0.80278177 -0.02321460
> > 15 1.144215 -0.04484519 -0.06084798 0.07633663
> > 32 1.213007 0.00741061 0.03896933 0.15325849
> > 23 1.274615 0.16477514 0.00872224 0.23128320
> > 41 1.215626 0.57050767 0.11415467 0.10608867
> > 43 1.134203 0.48070741 0.72112899 0.18108193
> > 12 1.091422 0.39563632 1.01521528 0.22597459
> > 21 1.100631 0.44589314 0.98526322 0.23535739
> > 35 1.226980 0.82419937 0.39809568 0.16900841
> >
> > NOW, I want to write a spline function where I can incorporate these
> > coefficients to get the predicted N concentration value for each day.
> > However, I am having trouble finding the right spline equation, since
> > there
> > are many forms on the internets.
> >
> > I know it won't be a simple one, but can some one direct me to the
> > equation
> > that would be best to use for ns?
> >
> > Thanks a lot,
> >
> > Ranae
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Do-YOU-know-an-
> equation-for-splines-ns-tp4632440p4632567.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list