Hello, I am very new to R. I would like to calculate a mean for a variable which is limited to a specific group of data which are defined by their values within another variable in the data set. How could I do this?
for example: "head_circ" in individuals whom are only in in "exp_group" 3
Thats great, thanks. Is there also a way to perform the calculations even if there is missing data for some of the individuals. In this case case taking the mean of the available data?
confint()function is aplicable for a fitted model object, not a numeric vector. I think you are trying to get a confidence interval for your mean, for a simple approach you can use a normal distribution, something like this.
filtered_data <- your_data$head_circ[your_data$exp_group == 3]
m <- mean(filtered_data, na.rm = TRUE)
s <- sd(filtered_data, na.rm = TRUE)
n <- length(filtered_data)
error <- qnorm(0.975)*s/sqrt(n)
left <- m-error
right <- m+error
Thanks thats excellent. When I then search for the outliers outside of this confidence interval there are exactly 10 individuals on either side of the confidence interval on analyses of 8 different parameters I have looked at using the following subset analysis, can this be correct?
Are you recalculating the left and right limits for each parameter? Remember that they where calculated for the mean of head_circ where exp_group == 3 only.
On the other hand, this approach might not be theoretically correct, if your are just doing exploratory analysis, this is fine, but be careful if your goal is to draw some conclusion from this analysis.