This is probably a very naive question... I'd like to estimate "adjusted" or "conditional" means for a variable (i'm unsure of the correct terminology). My data are on cortisol levels (dependent variable) in rabbits (n=56). I have many measurements at different times of the day, over many months. I'd like to calculate mean weekly values of cortisol for each individual rabbit so these can be used as a predictor in another model for which I only have weekly data. Rather than calculate the means from the raw data, i'd like to control for the time of day the samples were taken (this can influence the measurement). I thought i'd regress time of day (in minutes from 00:00 each day) on cortisol level and then extract the fitted values and calculate the weekly mean for each rabbit from these. Would this give me the estimated mean for cortisol, while controlling for time of day?
I can't share my data, but i've created a similar mock up using the iris data set. Here I fit a model, extract the fitted values and then calculate "adjusted" means for each species while controlling for the predictor. Am I right in thinking the difference between these means and the ones for the raw data (below) reflect the adjustment made when controlling for the independent variable?
data(iris) fit <- lm(Sepal.Length ~ Petal.Length, data = iris) summary(fit) with(iris, plot(Sepal.Length ~ Petal.Length, col = as.numeric(Species), asp = 1)) abline(coef(fit)) iris$fitted <- fitted(fit) with(iris, aggregate(fitted, list(Species), mean)) # Group.1 x # 1 setosa 4.9044 # 2 versicolor 6.0486 # 3 virginica 6.5769 with(iris, aggregate(Sepal.Length, list(Species), mean)) # Group.1 x # 1 setosa 5.006 # 2 versicolor 5.936 # 3 virginica 6.588