AllenDowney / ThinkStats2

Text and supporting code for Think Stats, 2nd Edition
http://allendowney.github.io/ThinkStats2/
GNU General Public License v3.0
4.03k stars 11.31k forks source link

SurvivalFunction class instantiation missing ss parameter in survival notebook #84

Closed gbremer closed 2 years ago

gbremer commented 7 years ago

In cell 3 of the survival notebook, the instantiation of a survival.SurvivalFunction class fails because it is missing the required second parameter, ss. The code in the notebook is --

cdf = thinkstats2.Cdf(complete, label='cdf')
sf = survival.SurvivalFunction(cdf, label='survival')
thinkplot.Plot(sf)
thinkplot.Config(xlabel='duration (weeks)', ylabel='survival function')
#thinkplot.Save(root='survival_talk1', formats=['png'])

The exception is --

08/29/2017 09:47:44 PM INFO: Running cell:
variables = GoMining(join)

08/29/2017 09:47:45 PM INFO: Cell raised uncaught exception: 
---------------------------------------------------------------------------
PatsyError                                Traceback (most recent call last)
<ipython-input-14-cb99e4bff205> in GoMining(df)
     16 
---> 17             model = smf.ols(formula, data=df)
     18             if model.nobs < len(df)/2:

~/anaconda/envs/thinkstats2-36/lib/python3.6/site-packages/statsmodels/base/model.py in from_formula(cls, formula, data, subset, drop_cols, *args, **kwargs)
    154         tmp = handle_formula_data(data, None, formula, depth=eval_env,
--> 155                                   missing=missing)
    156         ((endog, exog), missing_idx, design_info) = tmp

~/anaconda/envs/thinkstats2-36/lib/python3.6/site-packages/statsmodels/formula/formulatools.py in handle_formula_data(Y, X, formula, depth, missing)
     64             result = dmatrices(formula, Y, depth, return_type='dataframe',
---> 65                                NA_action=na_action)
     66         else:

~/anaconda/envs/thinkstats2-36/lib/python3.6/site-packages/patsy/highlevel.py in dmatrices(formula_like, data, eval_env, NA_action, return_type)
    311     if lhs.shape[1] == 0:
--> 312         raise PatsyError("model is missing required outcome variables")
    313     return (lhs, rhs)

PatsyError: model is missing required outcome variables

During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
<ipython-input-15-ba2f7ffb2f05> in <module>()

The class code snippet is --

class SurvivalFunction(object):
    """Represents a survival function."""

    def __init__(self, ts, ss, label=''):
        self.ts = ts
        self.ss = ss
        self.label = label

This is failing with a new install of Anaconda Python 2.7, and I would expect this to fail in Python 3 as well.