%FUELTEMPWIND1: MATLAB script M-file that computes parameter 
%values for a multilinear fit to the fuel-temperature-wind 
%example from "Probability and Statistical Inference, vol. 2:
%Statistical Inference," by J. G. Kalbfleisch (see p. 249).
fuel = [14.96 14.1 23.76 13.2 18.6 16.79 21.83 16.25 20.98 16.88]
temp = [-3 -1.8 -10 .7 -5.1 -6.3 -15.5 -4.2 -8.8 -2.3]
wind = [15.3 16.4 41.2 9.7 19.3 11.4 5.9 24.3 14.7 16.1]
%
F=[ones(size(fuel))' temp' wind']
%Check invertibility of F'*F
det(F'*F)
%Brute force calculation of p
p = inv(F'*F)*F'*fuel'
%MATLAB calculation of p (much more efficient)
pmat=F\fuel'
%SSR
ssr = norm(fuel'-F*p)^2
%Standard deviation for the fit
q = length(fuel)-length(p);
s = sqrt(ssr/q)
%R-squared calculations
fuelbar = mean(fuel);
T = norm(fuel-fuelbar)^2;
%Coefficient of determination
Rsq = 1-ssr/T
%Adjusted coefficient of determination
Rsqa = 1-(1-Rsq)*(length(fuel)-1)/q
