[R] Dealing with NA's in a data matrix
Daniel Malter
daniel at umd.edu
Tue Sep 6 09:03:34 CEST 2011
Please provide the data as self-contained code, as requested in the posting
guide, so that helpers can directly paste it into R. Alternatively, you can
provide the dilomaaethiops.txt.
Best,
Daniel
Watching19 wrote:
>
> hello... I am trying to get this code to work, but as I get to the predict
> command, it displays an error due to the length of the data sets from the
> removal of the NA's. Here is the data, and the code that I am using so
> far, if you run it, you'll see the error pop up.... please help me to get
> around this problem. Thanks in advance.
>
> Location Dist. Size
> low1 .5 10.5
> low2 .5 23
> low3 .5 NA
> low4 .5 NA
> mid1 3 15
> mid2 3 11.5
> mid3 3 15
> mid4 3 NA
> high1 6 12.5
> high2 6 20
> high3 6 21
> high4 6 22
> wall1 10 13
> wall2 10 12.5
> wall3 10 13
> wall4 10 12
>
> d<-read.table("dilomaaethiops.txt",header=T)
> d
> str(d)
> range(d$Dist.)
> s<-d$Size
> range(s)
> s[s<.1]<-NA
> range(s,na.rm=T)
> summary(d)
> length(s)
> length(d$Dist.)
> plot(s~d$Dist.,xlab="Distance from Shoreline (m)",ylab="D. aethiops Size
> (mm)", pch=7)
> a1<-glm(s~d$Dist.,family="quasipoisson",data=d)
> scatter.smooth(d$Dist.,s,ylab="D. aethiops Length (mm)",xlab="Distance
> from
> Shoreline (m)",col="red")
> summary(a1)
> a2<-aov(s~d$Dist.,data=d)
> summary(a2)
> shapiro.test(a2$residuals)
> qqnorm(a2$residuals)
> qqline(a2$residuals)
> fligner.test(s~d$Dist.,data=d)
> kruskal.test(s~d$Dist.,data=d)
> df<-df.residual(a1)
> t<-qt(.975,df)
> k<-data.frame(s=seq(10.5,max(s,na.rm=T),1))
> p<-predict(a1,k,se=T)
> est<-exp(p$fit)
> low<-exp(p$fit-t*p$se.fit)
> hight<-exp(p$fit-t*p$se.fit)
> plot(d$Dist.,s,ylim=c(min(s),max(s)),xlab="Distance from Shorline (m)",
> ylab="Length of D. aethiops (mm)", pch=7)
> lines(k$s,est,lty=1,col="red")
> lines(k$s,low,lty=2,col="blue")
> lines(k$s,high,lty=2,col="blue")
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
View this message in context: http://r.789695.n4.nabble.com/Dealing-with-NA-s-in-a-data-matrix-tp3791462p3792737.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list