## ## Protocol for estimating "known variance" FGLS regression model for ## estimated dependent variables in R. ## ## As described in: ## Jeffrey B. Lewis and Drew A. Linzer. 2005. "Estimating Regression ## Models in which the Dependent Variable Is Based on Estimates," ## Political Analysis. 13(4): 345-364. ## ## Jeffrey Lewis (jblewis@ucla.edu) ## Drew Linzer (dlinzer@ucla.edu) ## Department of Political Science ## University of California, Los Angeles ## ## The "known-variance" FGLS estimator simply requires some matrix algebra to ## calculate weights, and then a weighted least squares regression. ## ## The first thing to do is produce estimated values of sigma-hat squared, ## following the second equation at the top of page 352 in our article. ## ## The command to do this in R is somewhat lengthy because of all the matrix ## multiplication; the way it's written here, ystar is the dependent variable, ## x is a matrix of the independent variables, and omegasq is a vector of the ## "known" variances of the dependent variable. Note that the x matrix should ## not have a leading column of 1's; the command cbind(1,x) affixes the 1's ## as needed for the matrix multiplication. Also be sure that you have ## installed library(MASS) and library(lasso2) prior to running these commands, ## or else R will give you an error message. ## library(MASS) library(lasso2) sigmahatsq <- (sum((residuals(lm(ystar~x)))^2) - sum(omegasq) + tr(ginv(t(cbind(1,x)) %*% cbind(1,x)) %*% t(cbind(1,x)) %*% (diag(N) * omegasq) %*% cbind(1,x)))/(N-ncol(x)-1) ## ## We then suggest doing a quick check to set sigmahatsq to 0 if its ## estimated value comes back as negative. ## if (sigmahatsq < 0) sigmahatsq <- 0 ## ## Finally, the FGLS model may be estimated as a weighted least squares ## as follows. (In our article, the equation for the weights is the ## third equation down on page 352.) ## model.FGLS <- lm(ystar~x,weights=(1/(omegasq+sigmahatsq)))