Here is the example: i have 5 groups (ie. quantiles), and I want to know the mean of each variable (i.e. glucose, cholesterol etc.). Is easy to calculate means of each variable, but I want to be age-adjusted since want to compare the groups.
What I did is created a regression model: fit <- lm(glucose ~ age)
Now I dont know what to do to get age-adjusted mean for glucose.
I am not sure what you mean exactly, but if you want to know what is the impact of say glucose controlling for age, the regression does that automatically in generating the slopes. If you want to know for descriptive purposes what is the mean age of a given level of a specific predictor, then the software likely allows you to calculate this by using average age BY the levels of that predictor. That should be in the descriptive section of your software.
One easy way to get the age-adjusted group means on some variable is to regress that variable on the group factor, suppressing the intercept, and adding age to the model. That would look something like this:
lm(glucose ~ 0 + group + age)
This model will have one coefficient for each group, plus a coefficient for the age predictor. The coefficient for each group is that group's age-adjusted mean on glucose.
Make sure that "group" is stored as a factor object, rather than as a numeric or character vector. This is important!
That will cause the "age-adjusted mean" to be the predicted value for the group when age=0. If you mean center age first then the group coefficients are the predicted values for the group at the average age.
Did you mean-center age first? How different are the groups in terms of age? Because if they do differ quite a bit then the adjusted means won't necessarily be close to the raw group means *if* age actually does have an influence.
Yeah - and that's what the code Jake gives you. If you're just comparing the groups it doesn't really matter if you mean center age or not - but mean centering does provide a more interpretable value for the adjusted group means though.
And what's the issue? You want to age-adjust the means. If your problem is that it changes the means... why are you age-adjusting?
Typically these age-adjusted means are mainly to provide a way to compare the groups at a common level - what you should be doing with them is comparing these numbers between groups. If the groups differ a lot in terms of age AND age does have a decent effect on the response then yes the age-adjusted means will be quite different from the raw means. If this is an issue for you then you really need to put more thought into what you actually want.