next up previous index
Next: Simulation Up: Choice Model Previous: Initialization   Index

Estimation

In order to estimate coefficients $ \beta$ from the above equations, we define a specification:

>>> from numpy import array
>>> from opus_core.equation_specification import EquationSpecification
>>> specification = EquationSpecification(
      coefficients = array([
        "beta01",      "beta12",         "beta03",    "beta13"
                          ]),
      variables = array([
        "constant","household.persons", "constant", "household.persons"
                        ]),
      equations = array([
           1,              2,                3,             3
                    ])
      )
Each of the arguments is an array where the $ i$ th element describes the $ i$ th coefficient in an equation determined by the $ i$ th element in the argument equations. For example, beta12 is a coefficient connected to the household variable ``persons'' in equation 2, and beta03 is a constant used in equation 3. The prefix ``household'' in the variable name specifies the name of the dataset households. In other words, we are using here a dataset-qualified name of an attribute explained in Section 22.1.3. An optional argument submodels can extend the specification to a model with multiple submodels. The EquationSpecification class is described in Section 22.6.1 in more detail.

Our estimation data must include an attribute specifying choices that households made:

>>> households.add_primary_attribute(data=[1,2,2,2,1,3,3,1,2,1], name="choice_id")

The estimation is done by passing the specification, the agent set for estimation and a name of the module that implements the actual estimation to the method estimate():

>>> coefficients, other_results = choicemodel.estimate(
                         specification, households, 
                         procedure="opus_core.bhhh_mnl_estimation")
Estimating Choice Model (from opus_core.choice_model): started on 
                                                    Wed Nov  5 12:04:17 2008
    submodel: -2
    Convergence achieved.
    Akaike's Information Criterion (AIC):  26.142396805
    Number of Iterations:  144
    ***********************************************
    Log-likelihood is:            -9.07119840248
    Null Log-likelihood is:       -10.9861228867
    Likelihood ratio index:       0.174303938155
    Adj. likelihood ratio index:  -0.189791752496
    Number of observations:       10
    Suggested |t-value| >         1.51742712939
    Convergence statistic is:     0.000990037670084
    -----------------------------------------------
    Coeff_names	estimate	std err		t-values
        beta01	0.432678	 3.14438	0.137604
        beta03	-4.51824	 21.7087	-0.208131
        beta12	0.180115	 1.72541	 0.10439
        beta13	 1.34052	 4.18176	0.320564
    ***********************************************
    Elapsed time:  0.064521 seconds
Estimating Choice Model (from opus_core.choice_model): completed.........0.1 sec
The estimation module given in the argument procedure is a child of EstimationProcedure (see Section 22.5.6), must contain a method run() and should return a dictionary with keys ''estimators'' and ``standard_errors'' respectively, that contain arrays of the estimated values and their standard errors, respectively. The estimate() method returns a tuple where the first element is an instance of class Coefficients and the second element is a dictionary with all results returned by the estimation procedure.

A coefficient object can be stored in a storage. For example, to store the computed coefficients as an ASCII file mycoef.tab in the directory defined in the storage object on page [*], do

>>> coefficients.write(out_storage=storage, out_table_name="mycoef")
Again, other types of storage can be used here.


next up previous index
Next: Simulation Up: Choice Model Previous: Initialization   Index
info (at) urbansim.org