ijyliu / ECMA-31330-Project

Econometrics and Machine Learning Group Project
2 stars 1 forks source link

Need to apply transformation to make PCR coefficients comparable? #25

Closed ijyliu closed 3 years ago

ijyliu commented 3 years ago

See https://stats.stackexchange.com/questions/241890/coefficients-of-principal-components-regression-in-terms-of-original-regressors

ijyliu commented 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)
ijyliu commented 3 years ago

I tried a small run with this estimator instead of just the PCR one unadjusted.

I'm now getting results similar to OLS mismeasured.

image

We might be able to do better than mismeasured OLS if we use Paul's DGP...

ijyliu commented 3 years ago

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

ijyliu commented 3 years ago

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.

image

paul-opheim commented 3 years ago

Why is there no error on x_2?

ijyliu commented 3 years ago

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 .

ijyliu commented 3 years ago

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.