Closed ijyliu closed 3 years ago
Code that might fix this:
def PCR_coeffs(y, X):
# Compute singular value decomposition
# I am doing this by hand
# Extract the V prime matrix only (the loadings). It will be p x p, as will be V itself.
_, _, V_prime = np.linalg.svd(X)
V = V_prime.T
# Regress on the first principal component, constructing it using the loadings
# X is N x p and the first column of V is p x 1
# Our r, or rank condition is 1
pcr_coeff = sm.OLS(y, (X@(V[:, 0]))).fit().params[0]
# We need to left-multiply by the V for interpretability: https://stats.stackexchange.com/questions/241890/coefficients-of-principal-components-regression-in-terms-of-original-regressors
# The first column of V will be p x 1 and the coeff we extracted is a scalar
pcr_adjusted = (V[:, 0]) * pcr_coeff
# Return the ols-equivalent values
return(pcr_adjusted)
I tried a small run with this estimator instead of just the PCR one unadjusted.
I'm now getting results similar to OLS mismeasured.
We might be able to do better than mismeasured OLS if we use Paul's DGP...
I guess the reason we are now getting similar results to OLS mismeasured is kind of because we are rescaling the PCR result to get an ols-like coefficient
Here's a new result using Paul's DGP and this transformation to imitate the implied OLS
Note I am really tinkering with the measurement error because I set the variance of ME for the main x_1 to be 100 and 0 for the x_2/second measurement of x.
Why is there no error on x_2?
Check the covariance matrix for the errors, I don’t remember if I put some in or not.
Anyway if I didn’t put some in it’s because I’m trying to give our estimator the best possible conditions to do well
On Tue, May 11, 2021 at 11:14 AM marionoro @.***> wrote:
Why is there no error on x_2?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ijyliu/ECMA-31330-Project/issues/25#issuecomment-838656415, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQCGE4JVWCX5FCMRXEKJKOLTNFCW3ANCNFSM44PJCGYA .
This rescaling is kind of sketchy and focus of the project has moved on to a separate independent variable of interest without ME, and covariates that have ME and are subject to PCA.
See https://stats.stackexchange.com/questions/241890/coefficients-of-principal-components-regression-in-terms-of-original-regressors