[R] R generated means are different from the boxplot!

Jhope jeanwaijang at gmail.com
Fri Apr 6 10:35:06 CEST 2012


Hi R-listers, 

1) I am having trouble understanding why the means I have calculated from
Aeventexhumed (A, B, and C) are different from the means showing on the
boxplot I generated (see attached).  I have added the script as to how my
data is organized. 

2) Also when I went through the data manually the means I calculated  for
each nesting event are slightly different than what I generated through R
(see below). 
A,  B,  C
0.2155051, 0.1288241, 0.1124618

Thanks in advance,

Jean

-----------------------------------------------
> require(plyr)
Loading required package: plyr
> resp <- read.csv(file.choose())
> envir <- read.csv(file.choose())
> resp <- resp[!is.na(resp$Aeventexhumed), ]
> resp$QuadratEvent <- paste(resp$QuadratID, resp$Aeventexhumed, sep="")
> resp$QuadratEvent <- as.character(resp$QuadratEvent)
> envir <- envir[!is.na(envir$Aeventexhumed), ]
> envir$QuadratEvent <- paste(envir$QuadratID, envir$Aeventexhumed, sep="")
> envir$QuadratEvent <- as.character(envir$QuadratEvent)
> ExDate <- Sector <- Quadrat <- Aeventexhumed <- NULL
> ST1 <- ST2 <- ST3 <- ST4 <- ST0 <- NULL
> Shells <- Hatchlings <- MaxHatch <- DeadHatch <- NULL
> Oldeggs <- TotalEggs <- QuadratEvent <- NULL
> for (q in unique(as.character(resp$QuadratEvent))) {
+     s <- resp[as.character(resp$QuadratEvent) == q, ]
+     ExDate <- c(ExDate, as.character(s$ExDate[1]))
+     Sector <- c(Sector, as.character(s$Sector[1]))
+     Quadrat <- c(Quadrat, as.character(s$Quadrat[1]))
+     Aeventexhumed <- as.character(c(Aeventexhumed,
as.character(s$Aeventexhumed[1])))
+     QuadratEvent<- c(QuadratEvent, q)
+     ST1 <- c(ST1, sum(s$ST1, na.rm=TRUE))
+     ST2 <- c(ST2, sum(s$ST2, na.rm=TRUE))
+     ST3 <- c(ST3, sum(s$ST3, na.rm=TRUE))
+     ST4 <- c(ST4, sum(s$ST4, na.rm=TRUE))
+     ST0 <- c(ST0, sum(s$ST0, na.rm=TRUE))
+     Shells <- c(Shells, sum(s$Shells, na.rm=TRUE))
+     Hatchlings <- c(Hatchlings, sum(s$Hatchlings, na.rm=TRUE))
+     MaxHatch <- c(MaxHatch, sum(s$MaxHatch, na.rm=TRUE))
+     DeadHatch <- c(DeadHatch, sum(s$DeadHatch, na.rm=TRUE))
+     Oldeggs <- c(Oldeggs, sum(s$Oldeggs, na.rm=TRUE))
+     TotalEggs <- c(TotalEggs, sum(s$TotalEggs, na.rm=TRUE))
+ }
> responses <- data.frame(QuadratEvent, ExDate, Sector, Quadrat,
+                         Aeventexhumed, ST0, ST1, ST2, ST3, ST4, Shells,
+                         Hatchlings, MaxHatch, DeadHatch, Oldeggs,
+                         TotalEggs, stringsAsFactors=FALSE)
> responses$QuadratEvent <- as.character(responses$QuadratEvent)
> data.to.analyze <- join(responses, envir, by="QuadratEvent")
> data.to.analyze$NotHatched <- data.to.analyze$TotalEggs -
> data.to.analyze$Shells
> data.to.analyze$Rayos <- paste("Rayos", data.to.analyze$Rayos, sep=".")

> Hsuccess <- Shells/TotalEggs
> tapply(Hsuccess, Aeventexhumed, mean, na.rm=TRUE)
        A         B         C 
0.2156265 0.1288559 0.1124327 
> boxplot(HSuccess ~ Aeventexhumed, data = data.to.analyze, col = "blue",
+         main = "Hatching Success of Arribadas in 2010",
+         xlab = "Arribada Event",
+         ylab = "Hatching Success % (Shells / Total Eggs)")

http://r.789695.n4.nabble.com/file/n4536926/hatch_Aeventexhumed.png 

--
View this message in context: http://r.789695.n4.nabble.com/R-generated-means-are-different-from-the-boxplot-tp4536926p4536926.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list