Ajata Paul
2012-Feb-05 19:05 UTC
[R] How to Calculate Percentage of Data within certain SD of Mean
How do you calculate the percentage of data within 2SD, 3SD, 4SD, 5SD, and
6SD of the mean? I used the following link as the data I'm working with:
nb10 <-
read.table("http://www.adjoint-functors.net/su/web/314/R/NB10") if
this helps answer my question. Can you please explain how to calculate the
SD's? Please be specific in which part of the function changes when
calculating the next SD up.
Thanks.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-Calculate-Percentage-of-Data-within-certain-SD-of-Mean-tp4359551p4359551.html
Sent from the R help mailing list archive at Nabble.com.
Pete Brecknock
2012-Feb-05 21:13 UTC
[R] How to Calculate Percentage of Data within certain SD of Mean
How about ....
# Read Data
nb10 <-
read.table("http://www.adjoint-functors.net/su/web/314/R/NB10")
# Calculate Stats
total = length(nb10[,1])
mean = mean(nb10[,1])
sd = sd(nb10[,1])
# Function ... nSD is the number of SD you are looking at
pData <- function(nSD){
lo = mean - nSD/2*sd
hi = mean + nSD/2*sd
percent = sum(nb10[,1]>=lo & nb10[,1]<=hi)/total *100
}
# Output ...
print(paste("Percent of data within 2 SD is ",pData(2),"%",
sep="")) # 86%
print(paste("Percent of data within 3 SD is ",pData(3),"%",
sep="")) # 93%
print(paste("Percent of data within 4 SD is ",pData(4),"%",
sep="")) # 96%
print(paste("Percent of data within 5 SD is ",pData(5),"%",
sep="")) # 97%
print(paste("Percent of data within 6 SD is ",pData(6),"%",
sep="")) # 98%
HTH
Pete
Ajata Paul wrote>
> How do you calculate the percentage of data within 2SD, 3SD, 4SD, 5SD, and
> 6SD of the mean? I used the following link as the data I'm working
with:
> nb10 <-
read.table("http://www.adjoint-functors.net/su/web/314/R/NB10") if
> this helps answer my question. Can you please explain how to calculate
> the SD's? Please be specific in which part of the function changes
when
> calculating the next SD up.
>
> Thanks.
>
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-Calculate-Percentage-of-Data-within-certain-SD-of-Mean-tp4359551p4359809.html
Sent from the R help mailing list archive at Nabble.com.