Trying to add example that estimates a basic linear regression model using SMM
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:
- 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
- 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
irisdata in R and thisSMM.jlpackage. How would I allow forns[link to a line in the aforementioned gist] to be larger than 150 (the number of rows iniris)?
Thanks a ton for all the help you've given me so far!
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!
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.