def model_repr(model): assert type(model) == ModelDesc out = [] def write(s): out.append(s) write('=' * 40) write('Population') write('-' * 40) write('Coef Priors:') for (coef, prior) in zip(model.population.coefs, model.population.priors): write('{:<15} | {}'.format(coef, family_repr(prior))) for i, group in enumerate(model.groups): write('=' * 40) write('Group {}'.format(i)) write('-' * 40) write('Factors: {}\nNum Levels: {}'.format(', '.join(group.columns), len(group.levels))) write('Corr. Prior: {}'.format(None if group.corr_prior is None else family_repr(group.corr_prior))) write('S.D. Priors:') for (coef, sd_prior) in zip(group.coefs, group.sd_priors): write('{:<15} | {}'.format(coef, family_repr(sd_prior))) write('=' * 40) write('Response') write('-' * 40) write('Family: {}'.format(family_repr(model.response.family))) write('Link:') write(' Parameter: {}'.format(model.response.family.link.param)) write(' Function: {}'.format(model.response.family.link.fn.name)) write('Priors:') for (param, prior) in zip(model.response.nonlocparams, model.response.priors): write('{:<15} | {}'.format(param.name, family_repr(prior))) write('=' * 40) return '\n'.join(out)
def check_family_matches_response(formula, metadata, family): assert type(metadata) == Metadata if not family_matches_response(formula, metadata, family): # TODO: This could be more informative. e.g. If choosing # Bernoulli fails, is the problem that the response is # numeric, or that it has more than two levels? error = 'The response distribution "{}" is not compatible with the type or contents of the response column "{}".' raise Exception(error.format(family_repr(family), formula.response))