I need to calculate the regression variance ($\sigma^2$) in order to estimate both the confidence intervals and the prediction intervals in a gls regression analysis. For the analysis, the covariance matrix ($V$) of the response variable ($y$) is known in advance, and so I use it directly as the weighting matrix (=$V^{-1}$) in the gls regression analysis.
The regression variance is a weighted sum of the residual error: $\sigma^2 = \frac{ (Y – X\beta)^T C^{-1} (Y – X\beta)}{n – p}$
My question/problem is how to determine the weighting matrix $C^{-1}$? $C$ cannot be set equal to $V$ since (according to the above equation) $C$ must be dimensionless while $V$ has the same units as $\sigma^2$.
Based on my reading of the literature and available texts, it seems that $C$ is the correlation matrix and is a scaled or normalized form of the covariance matrix $V$. i.e., $V = Var(\epsilon^2) = \sigma^2 C$. But my problem is that $\sigma^2$ is not yet known, and so I need another way find $C$ from $V$.
R functions such as gls() will compute the regression variance (if I knew how gls() does this, it would answer my question). However I cannot use gls() in this case since I am specifying a user-defined covariance (weighting) matrix, and gls() only accepts a limited set of specific correlation structures.
In fact a possible solution can be found in this earlier post where an equation for the SEE (or sigma2) for a GLS regression was cited :
GLS calc of SEE: sqrt( sum( ( residuals from linear model) ^ 2 * glsWeight ) ) / sum( glsWeight ) * length( glsWeight ) / residualDegreeFreedom )
However I am unable to ascertain the validity of this equation and cannot find its source reference.