Models for Survival and Duration Analysis

Models for Survival and Duration Analysis Examples import statsmodels.api as sm import statsmodels.formula.api as smf data = sm.datasets.get_rdataset("flchain", "survival").data del data["chapter"] data = data.dropna() data["lam"] = data["lambda"] data["female"] = (data["sex"] == "F").astype(int) data["year"] = data["sample.yr"] - min(data["sample.yr"]) status = data["death"].values mod = smf.phreg("futime ~ 0 + age + female + creatinine + " "np.sqrt(kappa) + np.sqrt(lam) + y

MNLogit.score()

statsmodels.discrete.discrete_model.MNLogit.score MNLogit.score(params) [source] Score matrix for multinomial logit model log-likelihood Parameters: params : array The parameters of the multinomial logit model. Returns: score : ndarray, (K * (J-1),) The 2-d score vector, i.e. the first derivative of the loglikelihood function, of the multinomial logit model evaluated at params. Notes for In the multinomial model the score matrix is K x J-1 but is returned as a flattened array to

MNLogit.predict()

statsmodels.discrete.discrete_model.MNLogit.predict MNLogit.predict(params, exog=None, linear=False) Predict response variable of a model given exogenous variables. Parameters: params : array-like 2d array of fitted parameters of the model. Should be in the order returned from the model. exog : array-like 1d or 2d array of exogenous values. If not supplied, the whole exog attribute of the model is used. If a 1d array is given it assumed to be 1 row of exogenous variables. If you only hav

MNLogit.pdf()

statsmodels.discrete.discrete_model.MNLogit.pdf MNLogit.pdf(eXB) [source] NotImplemented

MNLogit.loglikeobs()

statsmodels.discrete.discrete_model.MNLogit.loglikeobs MNLogit.loglikeobs(params) [source] Log-likelihood of the multinomial logit model for each observation. Parameters: params : array-like The parameters of the multinomial logit model. Returns: loglike : ndarray (nobs,) The log likelihood for each observation of the model evaluated at params. See Notes Notes for observations where if individual i chose alternative j and 0 if not.

MNLogit.loglike_and_score()

statsmodels.discrete.discrete_model.MNLogit.loglike_and_score MNLogit.loglike_and_score(params) [source] Returns log likelihood and score, efficiently reusing calculations. Note that both of these returned quantities will need to be negated before being minimized by the maximum likelihood fitting machinery.

MNLogit.loglike()

statsmodels.discrete.discrete_model.MNLogit.loglike MNLogit.loglike(params) [source] Log-likelihood of the multinomial logit model. Parameters: params : array-like The parameters of the multinomial logit model. Returns: loglike : float The log-likelihood function of the model evaluated at params. See notes. Notes where if individual i chose alternative j and 0 if not.

MNLogit.jac()

statsmodels.discrete.discrete_model.MNLogit.jac MNLogit.jac(*args, **kwds) jac is deprecated, use score_obs instead! Use score_obs method. jac will be removed in 0.7 Jacobian matrix for multinomial logit model log-likelihood Parameters: params : array The parameters of the multinomial logit model. Returns: jac : ndarray, (nobs, k_vars*(J-1)) The derivative of the loglikelihood for each observation evaluated at params . Notes for , for observations In the multinomial model the sc

MNLogit.initialize()

statsmodels.discrete.discrete_model.MNLogit.initialize MNLogit.initialize() Preprocesses the data for MNLogit.

MNLogit.from_formula()

statsmodels.discrete.discrete_model.MNLogit.from_formula classmethod MNLogit.from_formula(formula, data, subset=None, *args, **kwargs) Create a Model from a formula and dataframe. Parameters: formula : str or generic Formula object The formula specifying the model data : array-like The data for the model. See Notes. subset : array-like An array-like object of booleans, integers, or index values that indicate the subset of df to use in the model. Assumes df is a pandas.DataFrame args :