MixedLM用于模型拟合

时间:2016-07-18 07:58:17

标签: python panel regression

我希望使用MixedLM将我的样本数据拟合到混合面板回归,但是对于我的输入sm.MixedLM.from_formula(“TOTCOST~YEAR”,dat,groups = dat [“NI”])我面临以下错误:< / p>

ValueError Traceback (most recent call last)
<ipython-input-40-38fa54e8b448> in <module>()
----> 1 sm.MixedLM.from_formula("TOTCOST~YEAR",dat,groups=dat["NI"])

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\statsmodels\regression\mixed_linear_model.pyc in from_formula(cls, formula, data, re_formula, subset, *args, **kwargs)
    651                                                subset=None,
    652                                                exog_re=exog_re,
--> 653                                                *args, **kwargs)
    654 
    655         # expand re names to account for pairs of RE

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\statsmodels\base\model.pyc in from_formula(cls, formula, data, subset, *args, **kwargs)
    145         (endog, exog), missing_idx = handle_formula_data(data, None, formula,
    146                                                          depth=eval_env,
--> 147                                                          missing=missing)
    148         kwargs.update({'missing_idx': missing_idx,
    149                        'missing': missing})

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\statsmodels\formula\formulatools.pyc in handle_formula_data(Y, X, formula, depth, missing)
     63         if data_util._is_using_pandas(Y, None):
     64             result = dmatrices(formula, Y, depth, return_type='dataframe',
---> 65                                NA_action=na_action)
     66         else:
     67             result = dmatrices(formula, Y, depth, return_type='dataframe',

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\patsy\highlevel.pyc in dmatrices(formula_like, data, eval_env, NA_action, return_type)
    295     eval_env = EvalEnvironment.capture(eval_env, reference=1)
    296     (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
--> 297                                       NA_action, return_type)
    298     if lhs.shape[1] == 0:
    299         raise PatsyError("model is missing required outcome variables")

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\patsy\highlevel.pyc in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
    150         return iter([data])
    151     design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env,
--> 152                                       NA_action)
    153     if design_infos is not None:
    154         return build_design_matrices(design_infos, data,

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\patsy\highlevel.pyc in _try_incr_builders(formula_like, data_iter_maker, eval_env, NA_action)
     55                                       data_iter_maker,
     56                                       eval_env,
---> 57                                       NA_action)
     58     else:
     59         return None

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\patsy\build.pyc in design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action)
    704                             factor_states[factor],
    705                             num_columns=num_column_counts[factor],
--> 706                             categories=None)
    707         else:
    708             assert factor in cat_levels_contrasts

C:\Users\Harshita Jaiswal\Anaconda2\lib\site-packages\patsy\design_info.pyc in __init__(self, factor, type, state, num_columns, categories)
     86         if self.type == "numerical":
     87             if not isinstance(num_columns, int):
---> 88                 raise ValueError("For numerical factors, num_columns "
     89                                  "must be an int")
     90             if categories is not None:

ValueError: For numerical factors, num_columns must be an int

任何帮助将不胜感激。谢谢

0 个答案:

没有答案