I'm using a linear model to predict a dependent variable (the score to a test) starting by the age of a person. As shown in the figure below, the variability decreases when the age increases (data are simulated!).
Since this characteristic trend of the variance, I'm using the Generalized Least Squares method implemented in R in the function gls() of the package nlme, by using the varExp variance function:
library("nlme")
vf <- varExp(form=~age)
fit <- gls(score~age, data=dataset, weights=vf)
The variance function provides a good distribution of residuals.
Now, I need to estimate, for some value of age, the corresponding value of the residual variance. However, the function predict() extracts only the fitted values, not the variances. There is a method to estimated the residual variance of each age, starting by the model?
?varWeights
function, although I don't think it will predict for new values of age ... $\endgroup$