Building standard errors in R

I have data on the catch rate of some species of fish.

fish 1 fish 2 fish 3 0.000 3.265 9.872 2.147 1.013 0.000 

I calculated the average catch rate for each fish using:

 a <- colMeans(df) 

I also calculated the standard error:

 stdError <- (sapply(df,sd))/sqrt(length(df)) 

I created dotplot using:

 dotplot(a, xlab="mean catch", ylab = "species",las =2,) 

How to add error lines to this graph? I would prefer not to use ggplot if possible. I am currently using built-in functions in R, but have access to Lattice.

Sorry for what is probably the main question, I'm brand new to the graphs in R.

+7
r
source share
1 answer

dotplot is a trellis function, and most default trellis functions do not have much support for confidence intervals. The Hmisc package extends most lattice functions to better include confidence intervals.

Here is an example of how you use it. Please note that we combine the data you want to build here in data.frame so that we can use the correct symtax ​​formula

 mm<-data.frame(a,stdError, fish=names(a)) library(lattice) library(Hmisc) Dotplot(fish~Cbind(a, a-stdError, a+stdError), mm, xlab="mean catch", ylab = "species",las =2) 

and it gives

enter image description here

Note that the version of the Hmisc function is called dotplot , and the version of lattice is called dotplot ; capitalization.

Here I just added / subtracted one standard error from the mean. You can calculate confidence intervals as you like.

+7
source share

All Articles