Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to add example that estimates a basic linear regression model using SMM #51

Open
tyleransom opened this issue Sep 26, 2020 · 2 comments

Comments

@tyleransom
Copy link

Hi @floswald, I'm getting more and more familiar with your package and I think it would be great to have some more examples (and, in particular, a regression example).

I've create a gist that attempts to do this. I will happily submit it as a PR to add to the examples if you're interested (and once it actually works!).

My example specifies the following moments to match:

  • E[y'X] in the data and E[y'X] in the model
  • V[y] in data and V[Xβ + ε] in the model (I specified this moment so as to be able to estimate the variance of the error term, like in the MSE formula)

This seems pretty easy to implement, but I am getting a couple of cryptic errors that I can't seem to resolve and was hoping it would be easy for you to spot where I'm going wrong:

  1. Undefined error for dataMomentWd:
┌ Warning: caught exception UndefVarError(:dataMomentWd) at param OrderedDict(:b0 => -0.302835267638089,:b1 => -0.3927639716972684,:b2 => -0.7839915331115677,:b3 => 0.3630821477120001,:s => 1.474363363563423)`
└ @ SMM ~/.julia/packages/SMM/MDWS3/src/mopt/mprob.jl:167
  1. No matter what I set for smpl_iters (it could be 100, 1_000 or 10_000), I always only get back 12 accepted draws

I couldn't see in the example files where dataMomentWd is defined, so that's why I'm getting the undefined error on that in my example.

I also had one other question about SMM in general (since this is my first foray into these types of models):

  • Does one usually simulate the X's in addition to drawing ε and using (X, β, ε) to generate y? The reason I ask is because the X's might have a different dimension than the number of draws of ε, so I can't seem to figure out how to resolve this. For example, suppose I wanted to estimate a regression using the iris data in R and this SMM.jl package. How would I allow for ns [link to a line in the aforementioned gist] to be larger than 150 (the number of rows in iris)?

Thanks a ton for all the help you've given me so far!

@floswald
Copy link
Owner

floswald commented Oct 1, 2020

sorry for the delay.

would be great to have your example as a PR, sure! I'm afraid most of your problems are related to lacking documentation, so apologies. you should file the PR even while it's not working, so we can make progress on it together.

the UndefVarError means the dataMomentWd function is not found there, which is strange.

Does one usually simulate the X's in addition to drawing ε and using (X, β, ε) to generate y? The reason I ask is because the X's might have a different dimension than the number of draws of ε, so I can't seem to figure out how to resolve this. For example, suppose I wanted to estimate a regression using the iris data in R and this SMM.jl package. How would I allow for ns [link to a line in the aforementioned gist] to be larger than 150 (the number of rows in iris)?

Good question. so, in general no. you keep all simulated sequences fixed at the same seed, in each run. because you want to be able to distinguish movements in the moment vector induced by parameter movements from other movements which were induced by different random sequences.
Not sure I understand what you want to do with the iris data: you would always use the X from that dataset, no?

all I know about this comes from Dean Corbae's website, in particular this here: https://sites.google.com/a/wisc.edu/deancorbae/research/HandoutEstimationF19.pdf?attredirects=0

there are a bunch of cool examples. i'm getting back into using this package now, so planning to extend docs and examples. would be great to have yours!

@tyleransom
Copy link
Author

Thanks for getting back to me, and no worries on the delay! This is a crazy time of the academic calendar.

Not sure I understand what you want to do with the iris data: you would always use the X from that dataset, no?

My question comes from me not understanding how to pass a data matrix into the objective function (see line 22 of the gist---I think I need to add X [the iris dataset] as an additional input).

I'll file this as a PR and we can keep iterating on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants