*
* NEURAL.RPF
* Example of estimation of a neural network.
*
* From User's Guide, Example from Section 13.3
*
open data probit.dat
data(org=obs) 1 95 public1_2 public3_4 public5 private $
years teacher loginc logproptax yesvm
*
* Linear probability model. Compute the "fitted" values. Because the LPM
* doesn't constrain the fitted values to the [0,1] range, some of them
* may be (and are) outside that.
*
linreg yesvm
# constant public1_2 public3_4 public5 private years teacher $
loginc logproptax
prj lpmfitted
*
* Probit model. Compute the fitted probabilities.
*
ddv(dist=probit) yesvm
# constant public1_2 public3_4 public5 private years teacher $
loginc logproptax
prj(distr=probit,cdf=prfitted)
*
* Neural network. We use two hidden nodes and one direct. (Two hidden
* nodes alone can't cover the space of values well enough). Note that the
* CONSTANT isn't included in the explanatory variables, since it's
* automatically included.
*
nnlearn(hidden=2,direct=1,iters=10000,save=nnmeth)
# public1_2 public3_4 public5 private years teacher $
loginc logproptax
# yesvm
*
* Compute the forecast values from the network.
*
nntest / nnmeth
# public1_2 public3_4 public5 private years teacher $
loginc logproptax
# testvm
*
* Compute the number of correct predictions for the various models
*
sstat(smpl=yesvm==0) / 1>>nos testvm<.5>>nnnos $
lpmfitted<.5>>lpmnos prfitted<.5>>prbnos
sstat(smpl=yesvm==1) / 1>>yes testvm>.5>>nnyes $
lpmfitted>.5>>lpmyes prfitted>.5>>prbyes
*
report(action=define,$
hlabels=||"Vote","Actual","Neural Net","LPM","Probit"||)
report(atcol=1) "No" nos nnnos lpmnos prbnos
report(atcol=1) "Yes" yes nnyes lpmyes prbyes
report(action=show)