[R] loess with missing data points
Gavin Simpson
gavin.simpson at ucl.ac.uk
Tue Oct 5 23:34:39 CEST 2010
On Tue, 2010-10-05 at 13:56 -0700, 1Rnwb wrote:
> Hello List,
> I have a longitudinal samples on multiple individuals, for initial analysis,
> i am doing some plots to see how the variable changes with the age. In some
> of the individuals one or two data points are missing,
> IL1Ra Age.at.Sample.Collection Subject.ID
> 6.575466 2.004106 00709-0
> NA 2.162902 00709-0
> 5.115421 3.312799 00709-0
> 6.119626 3.515400 00709-0
> 5.705648 4.156057 00709-0
> 7.298887 4.405201 00709-0
> 6.195063 4.577686 00709-0
> 6.574864 5.541409 00709-0
> When I run
> cap<-paste(sub.id,cases2$group[1],sep=" ")
> plot(cases2$IL1Ra~cases2$Age.at.Sample.Collection, ylab="eo_conc",xlab="Age
> at Sample",pch=1, ylim=c(3,10), xlim=c(0,22),main=cap)
> points(cases2$MIP1b~cases2$Age.at.Sample.Collection,pch=2,ylim=c(1.5,10),col="red")
> points(cases2$MCP1~cases2$Age.at.Sample.Collection,,pch=3,
> ylim=c(1.5,10),col="brown")
> lines(predict(loess(cases2$IL1Ra~cases2$Age.at.Sample.Collection))~cases2$Age.at.Sample.Collection,
> lwd=1, lty=1)
> lines(predict(loess(cases2$MIP1b~cases2$Age.at.Sample.Collection))~cases2$Age.at.Sample.Collection,
> col="red", lwd=1, lty=1)
> lines(predict(loess(cases2$MCP1~cases2$Age.at.Sample.Collection))~cases2$Age.at.Sample.Collection,col="brown",
> lwd=1, lty=1)
>
> I get error
> Error in model.frame.default(formula = predict(loess(cases2$IL1Ra ~
> cases2$Age.at.Sample.Collection)) ~ :
> variable lengths differ (found for 'cases2$Age.at.Sample.Collection')
> In addition: There were 50 or more warnings (use warnings() to see the first
> 50)
>
> I tried using na.action=na.omit, which is not working at all.
>
> I would appreciate some pointers in this regards to get these charts.
> Thanks
That's the second time this has come up today. Try
na.action = na.exclude
instead of na.omit in you loess() call. na.exclude will remove the NA
from the data used to fit the model, but ensure theye are put back in to
the results extracted from the loess model using the predict() extractor
function.
HTH
G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list