Hide keyboard shortcuts

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"""Longley dataset""" 

2from statsmodels.datasets import utils as du 

3 

4__docformat__ = 'restructuredtext' 

5 

6COPYRIGHT = """This is public domain.""" 

7TITLE = __doc__ 

8SOURCE = """ 

9The classic 1967 Longley Data 

10 

11http://www.itl.nist.gov/div898/strd/lls/data/Longley.shtml 

12 

13:: 

14 

15 Longley, J.W. (1967) "An Appraisal of Least Squares Programs for the 

16 Electronic Comptuer from the Point of View of the User." Journal of 

17 the American Statistical Association. 62.319, 819-41. 

18""" 

19 

20DESCRSHORT = """""" 

21 

22DESCRLONG = """The Longley dataset contains various US macroeconomic 

23variables that are known to be highly collinear. It has been used to appraise 

24the accuracy of least squares routines.""" 

25 

26NOTE = """:: 

27 

28 Number of Observations - 16 

29 

30 Number of Variables - 6 

31 

32 Variable name definitions:: 

33 

34 TOTEMP - Total Employment 

35 GNPDEFL - GNP deflator 

36 GNP - GNP 

37 UNEMP - Number of unemployed 

38 ARMED - Size of armed forces 

39 POP - Population 

40 YEAR - Year (1947 - 1962) 

41""" 

42 

43 

44 

45def load(as_pandas=None): 

46 """ 

47 Load the Longley data and return a Dataset class. 

48 

49 Parameters 

50 ---------- 

51 as_pandas : bool 

52 Flag indicating whether to return pandas DataFrames and Series 

53 or numpy recarrays and arrays. If True, returns pandas. 

54 

55 Returns 

56 ------- 

57 Dataset instance 

58 See DATASET_PROPOSAL.txt for more information. 

59 """ 

60 return du.as_numpy_dataset(load_pandas(), as_pandas=as_pandas) 

61 

62 

63def load_pandas(): 

64 """ 

65 Load the Longley data and return a Dataset class. 

66 

67 Returns 

68 ------- 

69 Dataset instance 

70 See DATASET_PROPOSAL.txt for more information. 

71 """ 

72 data = _get_data() 

73 return du.process_pandas(data, endog_idx=0) 

74 

75 

76def _get_data(): 

77 data = du.load_csv(__file__, 'longley.csv') 

78 data = data.iloc[:, [1, 2, 3, 4, 5, 6, 7]].astype(float) 

79 return data