# Confidence interval for variance in fit

When using (Non)LinearModelFit you can get estimates for all parameters and for the variance of the fit and confidence intervals for parameters, but what about a confidence interval for the variance?

Y = vout; (*vin, vout properly defined earlier*)
listn = Table[1, {i, 1, Length[Y]}];
A = Transpose[{listn, vin}]; (*design matrix*)
gammacap = Inverse[Transpose[A] . A] . Transpose[A] . Y
DF = Length[Y] - Length[gammacap]
vcap = Norm[Y - A . gammacap]^2/DF

a = 0.05; (*level of significance*)
qp = Quantile[ChiSquareDistribution[DF], 1 - a/2]
qm = InverseCDF[ChiSquareDistribution[DF], a/2]
t = Quantile[StudentTDistribution[DF], 1 - a/2]
da = t Sqrt[
Transpose[{1, 0}] . Inverse[Transpose[A] . A] . {1, 0}* vcap];
db = t Sqrt[
Transpose[{0, 1}] . Inverse[Transpose[A] . A] . {0, 1}* vcap];

intconfv = {DF vcap/qp, DF vcap/qm}
intconfa = {gammacap[[1]] - da, gammacap[[1]] + da}
intconfb = {gammacap[[2]] - db, gammacap[[2]] + db}


This is what I've been doing (formulas are taken from "Introduction to Probability and Statistics" of Georgii). I'm trying to not blindly use Mathematica's result, instead I wanted to understand the calculations behind those and indeed confidence intervals for parameters coincide with the ones obtained from

fit["ParameterConfidenceIntervalTable", ConfidenceLevel -> 0.95]


Is there an option for the confidence interval of variance (for the moment I'm studying the linear case) ?

• Do you mean the confidence interval for the error variance of the model or for the individual squares of the standard errors of the parameter estimates?
– JimB
Feb 24, 2021 at 4:00

Consider one of the examples in the documentation for LinearModelFit:

SeedRandom[12345];
data = Map[{#[[1]], #[[2]], #[[3]],
1.2 + (3.7 + RandomReal[{-1, 1}]) #[[1]] - 2 #[[2]] 23.4 #[[3]]} &, RandomReal[10, {100, 3}]];
lm = LinearModelFit[data, {x, y, z}, {x, y, z}];

(* Estimate of variance *)
variance = lm["EstimatedVariance"]
(* 12.6157 *)

(* 95% confidence intervals for variance *)
α = 0.05;
dfError = lm["ANOVATableDegreesOfFreedom"][[-2]];
{lowerCL, upperCL} = dfError*variance/
InverseCDF[ChiSquareDistribution[dfError], #] & /@ {1 - α/2, α/2}
(* {9.68888, 17.1102} *)