[R] Problem with NA data when computing standard error

apcoble coble.adam at gmail.com
Thu Apr 5 20:32:28 CEST 2012


I found a rather easy solution that circumvents this problem by: 

1) creating your own length function using na.omit function
2) calculating variance using tapply 
3) calculating length using new length function
4) calculating square root  of variance by length

*Code from LeCzar:*
 
object1<-as.data.frame.table(tapply(Data[Year=="1999"],na.rm=T,list(Group[Year=="1999"],Season[Year=="1999"]),mean)) 

object2<-as.data.frame.table(tapply(Data[Year=="1999"],na.rm=T,list(Group[Year=="1999"],Season[Year=="1999"]),se))

*Recommended code and round-about way to calculate se:*
1)
length.NA<-function(x)length(na.omit(x))

2)

object2.var<-as.data.frame.table(tapply(Data[Year=="1999"],na.rm=T,list(Group[Year=="1999"],Season[Year=="1999"]),var,na.rm=T))

3)
object2.length<-as.data.frame.table(tapply(Data[Year=="1999"],na.rm=T,list(Group[Year=="1999"],Season[Year=="1999"]),length.NA))

4)
sqrt(object2.var/object2.length) 

This should give you SE for your parameters.  For some reason,  the revised
length function doesn't work when I created an SE function, but it worked
well when I calculated length.  

--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-NA-data-when-computing-standard-error-tp855227p4535672.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list