jmbejara / comp-econ-sp18

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2018)
16 stars 23 forks source link

MLS and OLS q11 #54

Closed Jacob-Bishop closed 6 years ago

Jacob-Bishop commented 6 years ago

I'm getting a floating point division by zero error (Runtime warning: invalid value encountered in double_scalars) when I try to minimize the negative log-likelihood. It seems to be triggered by very small sigmas. However, my answer from 12 suggests that the true sigma is close to zero, so I can't just eliminate these by setting bounds on the optimization. Any suggestions?

jmbejara commented 6 years ago

I'm getting runtime errors too, but my estimates and their standard errors match the OLS results.---including my estimates for sigma. I find that when I put bounds on the optimizer, the standard errors don't work. I'm not sure why. I'm using

beta_0_init = 0
beta_1_init  = 0
beta_2_init  = 0
beta_3_init  = 0
sigma_init = 1

for my initial conditions.

Jacob-Bishop commented 6 years ago

So if I don't put bounds on the optimizer, I get x: array([ 0.e+00, 1.e-07, 1.e-01, -2.e+00, 4.e+00]). I don't get runtime errors if sigma is bounded to be >= 4.

The precise error is: C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\optimize.py:643: RuntimeWarning: invalid value encountered in double_scalars grad[k] = (f(*((xk + d,) + args)) - f0) / d[k]

jmbejara commented 6 years ago

This is what my results look like:

image

image

jmbejara commented 6 years ago

Here is some of my code:

# get  a log likelihood for a regression using certain parameters and 
# certain data
def neg_log_lik_reg(params, *data):
    beta_0, beta_1, beta_2, beta_3, sigma = params
    sick, age, children, temp = data
    xvals = sick - beta_0 - beta_1 * age - beta_2 * children - beta_3 * temp
    log_lik_val = log_lik_norm(xvals, mu=0, sigma=sigma)
    return -log_lik_val
Jacob-Bishop commented 6 years ago

I'm doing ~ the same things, but my results aren't that nice. I sent you my code if you have a sec to look at it.

Jacob-Bishop commented 6 years ago

Fixed, I was missing a - sign.