Skip to content

Commit

Permalink
Merge pull request #10 from rickecon/main
Browse files Browse the repository at this point in the history
Merging
  • Loading branch information
rickecon authored Oct 27, 2023
2 parents d165818 + 2967598 commit 10b3f49
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.5] - 2023-10-27 05:00:00

### Added
- Updates the Basic Empirical Methods section

## [0.0.4] - 2023-10-27 02:00:00

### Added
Expand Down Expand Up @@ -38,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



[0.0.5]: https://github.com/OpenSourceEcon/CompMethods/compare/v0.0.4...v0.0.5
[0.0.4]: https://github.com/OpenSourceEcon/CompMethods/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/OpenSourceEcon/CompMethods/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/OpenSourceEcon/CompMethods/compare/v0.0.1...v0.0.2
Expand Down
398 changes: 398 additions & 0 deletions data/BasicEmpirMethods/Auto.csv

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/book/CompMethods_references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ @BOOK{HumpherysJarvis:2020
volume = {2},
}

@Book{JamesEtAl:2017,
AUTHOR = {Gareth James and Daniela Witten and Trevor Hastie and Robert Tibshirani},
TITLE = {An Introduction to Statistical Learning with Applications in R},
PUBLISHER = {Springer},
YEAR = {2017},
series = {Springer Texts in Statistics},
}

@BOOK{Judd:1998,
AUTHOR = {Kenneth L. Judd},
TITLE = {Numerical Methods in Economics},
Expand Down
2 changes: 1 addition & 1 deletion docs/book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parts:
- file: git/intro
- caption: Basic Causal Inference
chapters:
- file: caus_inf/intro
- file: caus_inf/BasicEmpirMethods
- caption: Basic Machine Learning
chapters:
- file: basic_ml/intro
Expand Down
60 changes: 60 additions & 0 deletions docs/book/caus_inf/BasicEmpirMethods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---

(Chap_BasicEmpirMethods)=
# Basic Empirical Methods

Put basic empirical methods here. {numref}`ExerBasicEmpir_MultLinRegress`


(SecBasicEmpirExercises)=
## Exercises

```{exercise-start} Multiple linear regression
:label: ExerBasicEmpir_MultLinRegress
:class: green
```
For this problem, you will use the 397 observations from the [`Auto.csv`](https://github.com/OpenSourceEcon/CompMethods/tree/main/data/BasicEmpirMethods/Auto.csv) dataset in the [`/data/BasicEmpirMethods/`](https://github.com/OpenSourceEcon/CompMethods/tree/main/data/BasicEmpirMethods) folder of the repository for this book.[^Auto] This dataset includes 397 observations on miles per gallon (`mpg`), number of cylinders (`cylinders`), engine displacement (`displacement`), horsepower (`horsepower`), vehicle weight (`weight`), acceleration (`acceleration`), vehicle year (`year`), vehicle origin (`origin`), and vehicle name (`name`).
1. Import the data using the [`pandas.read_csv()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) function. Look for characters that seem out of place that might indicate missing values. Replace them with missing values using the `na_values=...` option.
2. Produce a scatterplot matrix which includes all of the quantitative variables `mpg`, `cylinders`, `displacement`, `horsepower`, `weight`, `acceleration`, `year`, `origin`. Call your DataFrame of quantitative variables `df_quant`. [Use the pandas scatterplot function in the code block below.]
```python
from pandas.plotting import scatter_matrix

scatter_matrix(df_quant, alpha=0.3, figsize=(6, 6), diagonal='kde')
```
3. Compute the correlation matrix for the quantitative variables ($8\times 8$) using the [`pandas.DataFrame.corr()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corr.html) method.
4. Estimate the following multiple linear regression model of $mpg_i$ on all other quantitative variables, where $u_i$ is an error term for each observation, using Python's `statsmodels.api.OLS()` function.
\begin{equation*}
\begin{split}
mpg_i &= \beta_0 + \beta_1 cylinders_i + \beta_2 displacement_i + \beta_3 horsepower_i + ... \\
&\qquad \beta_4 weight_i + \beta_5 acceleration_i + \beta_6 year_i + \beta_7 origin_i + u_i
\end{split}
\end{equation*}
* Which of the coefficients is statistically significant at the 1\% level?
* Which of the coefficients is NOT statistically significant at the 10\% level?
* Give an interpretation in words of the estimated coefficient $\hat{\beta}_6$ on $year_i$ using the estimated value of $\hat{\beta}_6$.
5. Looking at your scatterplot matrix from part (2), what are the three variables that look most likely to have a nonlinear relationship with $mpg_i$?
* Estimate a new multiple regression model by OLS in which you include squared terms on the three variables you identified as having a nonlinear relationship to $mpg_i$ as well as a squared term on $acceleration_i$.
* Report your adjusted R-squared statistic. Is it better or worse than the adjusted R-squared from part (4)?
* What happened to the statistical significance of the $displacement_i$ variable coefficient and the coefficient on its squared term?
* What happened to the statistical significance of the cylinders variable?
6. Using the regression model from part (5) and the `.predict()` function, what would be the predicted miles per gallon $mpg$ of a car with 6 cylinders, displacement of 200, horsepower of 100, a weight of 3,100, acceleration of 15.1, model year of 1999, and origin of 1?
```{exercise-end}
```


(SecBasicEmpirFootnotes)=
## Footnotes

The footnotes from this chapter.

[^Auto]: The [`Auto.csv`](https://github.com/OpenSourceEcon/CompMethods/tree/main/data/BasicEmpirMethods/Auto.csv) dataset comes from {cite}`JamesEtAl:2017` (ch. 3) and is also available at http://www-bcf.usc.edu/~gareth/ISL/data.html.
10 changes: 0 additions & 10 deletions docs/book/caus_inf/intro.md

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="CompMethods",
version="0.0.4",
version="0.0.5",
author="Richard W. Evans",
author_email="rickecon@gmail.com",
long_description=readme,
Expand Down

0 comments on commit 10b3f49

Please sign in to comment.