so this is the code i used when i wanted to find "what proportion of these numbers are within one standard deviation away from the list's average?" :
library(dplyr)
bodyweights <- dat$Bodyweight
mean_bodyweights <- mean(bodyweights)
sd_bodyweight <- sd(bodyweights)
lower_bound <- mean_bodyweights - sd_bodyweight
upper_bound <- mean_bodyweights + sd_bodyweight
proportion_with1sd <- pnorm(upper_bound, mean_bodyweights, sd_bodyweight) - pnorm(lower_bound, mean_bodyweights, sd_bodyweight)
print(proportion_with1sd)
#> [1] 0.6826895
and the question that followed up asked "Define y to be the weights of males on the control diet.
What proportion of the mice are within one standard deviation away from the average weight?" and this was what i wrote:
library(dplyr)
male_chow_data <- dat %>%
filter(Sex == "M" & Diet == "chow")
y <- male_chow_data$Bodyweight
mean_weight_chow <- mean(y)
sd_weight_chow <- popsd(y)
lower_bound <- mean_weight_chow - sd_weight_chow
upper_bound <- mean_weight_chow + sd_weight_chow
proportion_within1sd <- pnorm(upper_bound, mean_weight_chow, sd_weight_chow) - pnorm(lower_bound, mean_weight_chow, sd_weight_chow)
print(proportion_within1sd)
#> [1] 0.6826895
I do not understand why i get the same answer? why is it not using the data which i specified as "male_chow_data" and is using the entire list?
I used the rm() function and did it all over again, yet i get the same response