ftest = function(model,L,h=0) # General linear test of H0: L beta = h { BetaHat = model$coefficients dimL = dim(L) if(length(BetaHat) != dimL[2]) stop("Sizes of L and Beta are incompatible") r = dimL[1] if(qr(L)$rank != r) stop("Rows of L must be linearly independent.") out = numeric(4) names(out) = c("F","df1","df2","p-value") dfe = df.residual(model) diff = L%*%BetaHat-h fstat = t(diff) %*% solve(L%*%vcov(model)%*%t(L)) %*% diff / r # Note vcov = MSE * XtXinv fstat = as.numeric(fstat) out[1] = fstat; out[2]=r; out[3]=dfe out[4] = 1-pf(fstat,r,dfe) return(out) } # End of function ftest