Wtest = function(L,Tn,Vn,h=0) # H0: L theta = h # Note Vn is the estimated asymptotic covariance matrix of Tn, # so it's Sigma-hat divided by n. For Wald tests based on numerical # MLEs, Tn = theta-hat, and Vn is the inverse of the Hessian. { Wtest = numeric(3) names(Wtest) = c("W","df","p-value") r = dim(L)[1] W = t(L%*%Tn-h) %*% solve(L%*%Vn%*%t(L)) %*% (L%*%Tn-h) W = as.numeric(W) pval = 1-pchisq(W,r) Wtest[1] = W; Wtest[2] = r; Wtest[3] = pval Wtest } # End function Wtest