Re: [R] Do YOU know an equation for splines (ns)?
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)?
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] Do YOU know an equation for splines (ns)?
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.
[R] splines and ns equation
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/splines-and-ns-equation-tp4631986.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] SSfol in nlme
Hello, I am using SSfol in nlme to fit some data for the change of N concentration (N) in plant tissue over time (gdd). The model works nicely for 2 out of 3 treatments, so I would really like to use it, but it consistently has a bad fit for my third treatment. I am pasting the figure for the third treatment only. I feel that I have my fixed and random effects properly identified, but have also tried many combinations to see if I can improve the fit. Are there any other ideas of what I can do to capture the highest point of N with the model? http://r.789695.n4.nabble.com/file/n4615613/Predicted_N_2.png Here is my code for the figure followed by a link to the dataset. library(nlme) cna-read.table(aboveground C and N, dates removed, zeros added.txt, header=TRUE) ###Aboveground 2011, treatment PF only n11a-subset(cna, cna$year == 2011 cna$ground == Above cna$trt == PF) n11a$plotF - as.factor(n11a$plot) n11aG-groupedData(N ~ gdd | plotF, data=n11a) fit.dose- nlsList(N ~ SSfol(dose, gdd, lke, lka, lCl), data = n11aG) plot(intervals(fit.dose), layout=c(3,1)) fit.nlme.11a- nlme(fit.dose, random=pdDiag(lCl ~ 1)) fit.nlme2.11a-update(fit.nlme.11a, random = list(lCl + lka ~ 1)) png(thermaltimefigs/Predicted N 1.png) plot(augPred(fit.nlme.11a), level = 0:1) dev.off() png(thermaltimefigs/Predicted N 2.png) plot(augPred(fit.nlme2.11a), level = 0:1) dev.off() data at: http://dl.dropbox.com/u/21080842/aboveground%20C%20and%20N%2C%20dates%20removed%2C%20zeros%20added.txt Thanks, Ranae -- View this message in context: http://r.789695.n4.nabble.com/SSfol-in-nlme-tp4615613.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] Fitting a first order compartment model in nlme
Hello, I am using SSfol in nlme to fit some data for the change of N concentration (N) in plant tissue over time (gdd). The model works nicely for 2 out of 3 treatments, so I would really like to use it, but it consistently has a bad fit for my third treatment. I am pasting the figure for the third treatment only. I feel that I have my fixed and random effects properly identified, but have also tried many combinations to see if I can improve the fit. Are there any other ideas of what I can do to capture the highest point of N with the model? http://r.789695.n4.nabble.com/file/n4601419/Predicted_N_2.png Here is my code for the figure followed by a link to the dataset. library(nlme) cna-read.table(aboveground C and N, dates removed, zeros added.txt, header=TRUE) ###Aboveground 2011, treatment PF only n11a-subset(cna, cna$year == 2011 cna$ground == Above cna$trt == PF) n11a$plotF - as.factor(n11a$plot) n11aG-groupedData(N ~ gdd | plotF, data=n11a) fit.dose- nlsList(N ~ SSfol(dose, gdd, lke, lka, lCl), data = n11aG) plot(intervals(fit.dose), layout=c(3,1)) fit.nlme.11a- nlme(fit.dose, random=pdDiag(lCl ~ 1)) fit.nlme2.11a-update(fit.nlme.11a, random = list(lCl + lka ~ 1)) png(thermaltimefigs/Predicted N 1.png) plot(augPred(fit.nlme.11a), level = 0:1) dev.off() png(thermaltimefigs/Predicted N 2.png) plot(augPred(fit.nlme2.11a), level = 0:1) dev.off() data at: http://dl.dropbox.com/u/21080842/aboveground%20C%20and%20N%2C%20dates%20removed%2C%20zeros%20added.txt Thanks, Ranae -- View this message in context: http://r.789695.n4.nabble.com/Fitting-a-first-order-compartment-model-in-nlme-tp4601419.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.