Re: [R] Do YOU know an equation for splines (ns)?

2012-06-11 Thread Ranae
I was able to get the predicted values from the splines.  Thanks so much
for the help.

I wrote a loop with some of the code that Bill suggested.  It seems that
when using predict with nlme, it is important to be specific with what one
is using as newdata.  This does come through in Pinheiro and Bates, I just
didn't recognize it to begin with.  Bert, I did try your code, but was only
getting coefficients, so I may have neglected a step.

##The successful code:
library(nlme)
library(splines)

rootCN-read.table(spline.txt, header=3DTRUE)
rootCN$plotF-as.factor(rootCN$plot)
rcn10G-groupedData(N ~ day | plotF, data=3DrootCN)

fit10 - lme( N~ns(day, 3), data =3D rcn10G)

plot(augPred(fit10))


t- 152:305
subject-rootCN[11:22,2]
sim-NULL
for(i in 1:12){
sim- cbind(sim, predict(fit10, data.frame(day=3Dt, plotF=3Drep(subject[i],
length(t)
}
colnames(sim) - c(subject)


par(mfrow=3Dc(4,3))
for(i in 1:12){
plot(t, sim[,i], type=3Dl, main=3Dsubject[i])
}


-Ranae

--
View this message in context: 
http://r.789695.n4.nabble.com/Do-YOU-know-an-equation-for-splines-ns-tp4632440p4633037.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Do YOU know an equation for splines (ns)?

2012-06-06 Thread Ranae
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 
 241.050360 -0.42666159 -0.56290877 -0.10714407 
 131.104464 -0.30825350 -0.53311653 -0.05558150 
 311.147878 -0.14548512 -0.78673906 -0.07231781 
 461.177781 -0.22278380 -0.80278177 -0.02321460 
 151.144215 -0.04484519 -0.06084798  0.07633663 
 321.213007  0.00741061  0.03896933  0.15325849 
 231.274615  0.16477514  0.00872224  0.23128320 
 411.215626  0.57050767  0.11415467  0.10608867 
 431.134203  0.48070741  0.72112899  0.18108193 
 121.091422  0.39563632  1.01521528  0.22597459 
 211.100631  0.44589314  0.98526322  0.23535739 
 351.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@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] Do YOU know an equation for splines (ns)?

2012-06-06 Thread Bert Gunter
Ah ...
Iirc believe the problem is that you need to explicitly generate the
spline basis and then the predicted values via predict.ns and feed
that to predict.lme; i.e.

splineBas - with(rcn10,ns(day,3))

newvals - data.frame( predict(splineBas, num))

## then once you've fitted your model:
lines(num, predict(fit10, newvals))


I have NOT checked this though, so please post back to me and the list
whether this works.

-- Bert




On Wed, Jun 6, 2012 at 10:38 AM, Ranae ranae.diet...@gmail.com wrote:
 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@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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] Do YOU know an equation for splines (ns)?

2012-06-06 Thread William Dunlap
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Ranae
 Sent: Wednesday, June 06, 2012 10:39 AM
 To: r-help@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
  241.050360 -0.42666159 -0.56290877 -0.10714407
  131.104464 -0.30825350 -0.53311653 -0.05558150
  311.147878 -0.14548512 -0.78673906 -0.07231781
  461.177781 -0.22278380 -0.80278177 -0.02321460
  151.144215 -0.04484519 -0.06084798  0.07633663
  321.213007  0.00741061  0.03896933  0.15325849
  231.274615  0.16477514  0.00872224  0.23128320
  411.215626  0.57050767  0.11415467  0.10608867
  431.134203  0.48070741  0.72112899  0.18108193
  121.091422  0.39563632  1.01521528  0.22597459
  211.100631  0.44589314  0.98526322  0.23535739
  351.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@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.

__
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] Do YOU know an equation for splines (ns)?

2012-06-06 Thread Spencer Graves
  I agree with Bill and Bert:  predict is the proper tool for 
making predictions.  Pinheiro and Bates (2000) Mixed-Effects Models in S 
and S-Plus (Springer) includes several entries in the index for 
predictions.  Please note, however, that there are a few lines of code 
in that book the work in S-Plus but not R.  Fortunately, the corrections 
are available in script files distributed with the package, which you 
can find as follows:




system.file('scripts', package='nlme')

[1] c:/Program Files/R/R-2.15.0/library/nlme/scripts


  The TaylorSpline{fda} function will give you explicit 
coefficients each segment of a spline.  However, if you want model 
predictions, you are probably best using predict with objects produced 
by functions in nlme.  That package has seen lots of use and attention 
by the R Core team, and should be pretty good -- especially with the 
documentation provided by Pinheiro and Bates.



  Hope this helps.
  Spencer


On 6/6/2012 1:48 PM, William Dunlap wrote:

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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of Ranae
Sent: Wednesday, June 06, 2012 10:39 AM
To: r-help@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
241.050360 -0.42666159 -0.56290877 -0.10714407
131.104464 -0.30825350 -0.53311653 -0.05558150
311.147878 -0.14548512 -0.78673906 -0.07231781
461.177781 -0.22278380 -0.80278177 -0.02321460
151.144215 -0.04484519 -0.06084798  0.07633663
321.213007  0.00741061  0.03896933  0.15325849
231.274615  0.16477514  0.00872224  0.23128320
411.215626  0.57050767  0.11415467  0.10608867
431.134203  0.48070741  0.72112899  0.18108193
121.091422  0.39563632  1.01521528  0.22597459
211.100631  0.44589314  0.98526322  0.23535739
351.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@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.

__
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

[R] Do YOU know an equation for splines (ns)?

2012-06-05 Thread Ranae
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 
241.050360 -0.42666159 -0.56290877 -0.10714407 
131.104464 -0.30825350 -0.53311653 -0.05558150 
311.147878 -0.14548512 -0.78673906 -0.07231781 
461.177781 -0.22278380 -0.80278177 -0.02321460 
151.144215 -0.04484519 -0.06084798  0.07633663 
321.213007  0.00741061  0.03896933  0.15325849 
231.274615  0.16477514  0.00872224  0.23128320 
411.215626  0.57050767  0.11415467  0.10608867 
431.134203  0.48070741  0.72112899  0.18108193 
121.091422  0.39563632  1.01521528  0.22597459 
211.100631  0.44589314  0.98526322  0.23535739 
351.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-tp4632440.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Do YOU know an equation for splines (ns)?

2012-06-05 Thread Bert Gunter
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 ranae.diet...@gmail.com 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-tp4632440.html
 Sent from the R help mailing list archive at Nabble.com.

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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