Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/statsmodels/datasets/cpunish/data.py : 65%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""US Capital Punishment dataset."""
2from statsmodels.datasets import utils as du
4__docformat__ = 'restructuredtext'
6COPYRIGHT = """Used with express permission from the original author,
7who retains all rights."""
8TITLE = __doc__
9SOURCE = """
10Jeff Gill's `Generalized Linear Models: A Unified Approach`
12http://jgill.wustl.edu/research/books.html
13"""
15DESCRSHORT = """Number of state executions in 1997"""
17DESCRLONG = """This data describes the number of times capital punishment is implemented
18at the state level for the year 1997. The outcome variable is the number of
19executions. There were executions in 17 states.
20Included in the data are explanatory variables for median per capita income
21in dollars, the percent of the population classified as living in poverty,
22the percent of Black citizens in the population, the rate of violent
23crimes per 100,000 residents for 1996, a dummy variable indicating
24whether the state is in the South, and (an estimate of) the proportion
25of the population with a college degree of some kind.
26"""
28NOTE = """::
30 Number of Observations - 17
31 Number of Variables - 7
32 Variable name definitions::
34 EXECUTIONS - Executions in 1996
35 INCOME - Median per capita income in 1996 dollars
36 PERPOVERTY - Percent of the population classified as living in poverty
37 PERBLACK - Percent of black citizens in the population
38 VC100k96 - Rate of violent crimes per 100,00 residents for 1996
39 SOUTH - SOUTH == 1 indicates a state in the South
40 DEGREE - An esimate of the proportion of the state population with a
41 college degree of some kind
43 State names are included in the data file, though not returned by load.
44"""
47def load_pandas():
48 """
49 Load the cpunish data and return a Dataset class.
51 Returns
52 -------
53 Dataset instance:
54 See DATASET_PROPOSAL.txt for more information.
55 """
56 data = _get_data()
57 return du.process_pandas(data, endog_idx=0)
60def load(as_pandas=None):
61 """
62 Load the cpunish data and return a Dataset class.
64 Parameters
65 ----------
66 as_pandas : bool
67 Flag indicating whether to return pandas DataFrames and Series
68 or numpy recarrays and arrays. If True, returns pandas.
70 Returns
71 -------
72 Dataset instance:
73 See DATASET_PROPOSAL.txt for more information.
74 """
75 return du.as_numpy_dataset(load_pandas(), as_pandas=as_pandas)
78def _get_data():
79 data = du.load_csv(__file__, 'cpunish.csv')
80 data = data.iloc[:, 1:8].astype(float)
81 return data