Hello dear R Community,
I am having some issues calculating the 95% confidence intervals for the mean prices of diamonds according to their depth. The data used were taken from the "Diamond" database (http://ggplot2.tidyverse.org/reference/diamonds.html) .
I don't know why, but I keep getting missing values (NA's) for my confidence intervals. I tried to calculate the confidence intervals with the R function "ci.mean"
(https://www.rdocumentation.org/packages/Publish/versions/2017.10.24/topics/ci.mean), but I got even more missing values.
It would be great if anyone could tell me why this keeps happening.
Here is my code:
diamonds %>% group_by(depth) %>% summarize( mean = mean(price), sd = sd(price), se = sdev / sqrt(length(price)), t <- qt(1-.025, df=(length(price)-1)), ci.lower = m - (t * stderr), ci.upper = m + (t * stderr)) -> results results
Many many thanks in advance!