class: center, middle, inverse, title-slide # ECON 3818 ## Chapter 26 ### Kyle Butts ### 27 September 2021 --- class: clear, middle <!-- Custom css --> <style type="text/css"> /* ------------------------------------------------------- * * !! This file was generated by xaringanthemer !! * * Changes made to this file directly will be overwritten * if you used xaringanthemer in your xaringan slides Rmd * ------------------------------------------------------- */ @import url(https://fonts.googleapis.com/css?family=Roboto&display=swap); @import url(https://fonts.googleapis.com/css?family=Roboto&display=swap); @import url(https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700&display=swap); @import url(https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible&display=swap); :root { /* Fonts */ --text-font-family: 'Atkinson Hyperelegible'; --text-font-is-google: 1; --text-font-family-fallback: Roboto, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial; --text-font-base: sans-serif; --header-font-family: 'Atkinson Hyperelegible' --header-font-is-google: 1; --header-font-family-fallback: Georgia, serif; --code-font-family: 'Source Code Pro'; --code-font-is-google: 1; --base-font-size: 20px; --text-font-size: 1rem; --code-font-size: 0.9rem; --code-inline-font-size: 1em; --header-h1-font-size: 1.75rem; --header-h2-font-size: 1.6rem; --header-h3-font-size: 1.5rem; /* Colors */ --text-color: #131516; --text-color-light: #555F61; --header-color: #FFF; --background-color: #FFF; --link-color: #107895; --code-highlight-color: rgba(255,255,0,0.5); --inverse-text-color: #d6d6d6; --inverse-background-color: #272822; --inverse-header-color: #f3f3f3; --inverse-link-color: #107895; --title-slide-background-color: #272822; --title-slide-text-color: #d6d6d6; --header-background-color: #FFF; --header-background-text-color: #FFF; } html { font-size: var(--base-font-size); } body { font-family: var(--text-font-family), var(--text-font-family-fallback), var(--text-font-base); font-weight: normal; color: var(--text-color); } h1, h2, h3 { font-family: var(--header-font-family), var(--header-font-family-fallback); color: var(--text-color-light); } .remark-slide-content { background-color: var(--background-color); font-size: 1rem; padding: 24px 32px 16px 32px; width: 100%; height: 100%; } .remark-slide-content h1 { font-size: var(--header-h1-font-size); } .remark-slide-content h2 { font-size: var(--header-h2-font-size); } .remark-slide-content h3 { font-size: var(--header-h3-font-size); } .remark-code, .remark-inline-code { font-family: var(--code-font-family), Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace; } .remark-code { font-size: var(--code-font-size); } .remark-inline-code { font-size: var(--code-inline-font-size); color: #000; } .remark-slide-number { color: #107895; opacity: 1; font-size: 0.9em; } a, a > code { color: var(--link-color); text-decoration: none; } .footnote { position: absolute; bottom: 60px; padding-right: 6em; font-size: 0.9em; } .remark-code-line-highlighted { background-color: var(--code-highlight-color); } .inverse { background-color: var(--inverse-background-color); color: var(--inverse-text-color); } .inverse h1, .inverse h2, .inverse h3 { color: var(--inverse-header-color); } .inverse a, .inverse a > code { color: var(--inverse-link-color); } img, video, iframe { max-width: 100%; } blockquote { border-left: solid 5px lightgray; padding-left: 1em; } @page { margin: 0; } @media print { .remark-slide-scaler { width: 100% !important; height: 100% !important; transform: scale(1) !important; top: 0 !important; left: 0 !important; } } /* Modified metropolis */ .clear{ border-top: 0px solid #FAFAFA; } h1 { margin-top: -5px; margin-left: -00px; margin-bottom: 30px; color: var(--text-color-light); font-weight: 200; } h2, h3, h4 { padding-top: -15px; padding-bottom: 00px; color: #1A292C; text-shadow: none; font-weight: 400; text-align: left; margin-left: 00px; margin-bottom: -10px; } .title-slide .inverse .remark-slide-content { background-color: #FAFAFA; } .title-slide { background-color: #FAFAFA; border-top: 80px solid #FAFAFA; } .title-slide h1 { color: var(--text-color); font-size: 40px; text-shadow: none; font-weight: 400; text-align: left; margin-left: 15px; } .title-slide h2 { margin-top: -15px; color: var(--link-color); text-shadow: none; font-weight: 300; font-size: 35px; text-align: left; margin-left: 15px; } .title-slide h3 { color: var(--text-color-light); text-shadow: none; font-weight: 300; font-size: 25px; text-align: left; margin-left: 15px; margin-bottom: 0px; } .title-slide h3:last-of-type { font-style: italic; font-size: 1rem; } /* Remove orange line */ hr, .title-slide h2::after, .mline h1::after { content: ''; display: block; border: none; background-color: #e5e5e5; color: #e5e5e5; height: 1px; } hr, .mline h1::after { margin: 1em 15px 0 15px; } .title-slide h2::after { margin: 10px 15px 35px 0; } .mline h1::after { margin: 10px 15px 0 15px; } /* turns off slide numbers for title page: https://github.com/gnab/remark/issues/298 */ .title-slide .remark-slide-number { display: none; } /* Custom CSS */ /* More line spacing */ body { line-height: 1.5; } /* Font styling */ .hi { font-weight: 600; } .mono { font-family: monospace; } .ul { text-decoration: underline; } .ol { text-decoration: overline; } .st { text-decoration: line-through; } .bf { font-weight: bold; } .it { font-style: italic; } /* Font Sizes */ .bigger { font-size: 125%; } .huge{ font-size: 150%; } .small { font-size: 95%; } .smaller { font-size: 85%; } .smallest { font-size: 75%; } .tiny { font-size: 50%; } /* Remark customization */ .clear .remark-slide-number { display: none; } .inverse .remark-slide-number { display: none; } .remark-code-line-highlighted { background-color: rgba(249, 39, 114, 0.5); } /* Xaringan tweeks */ .inverse { background-color: #23373B; text-shadow: 0 0 20px #333; /* text-shadow: none; */ } .title-slide { background-color: #ffffff; border-top: 80px solid #ffffff; } .footnote { bottom: 1em; font-size: 80%; color: #7f7f7f; } /* Lists */ li { margin-top: 4px; } /* Mono-spaced font, smaller */ .mono-small { font-family: monospace; font-size: 16px; } .mono-small .mjx-chtml { font-size: 103% !important; } .pseudocode, .pseudocode-small { font-family: monospace; background: #f8f8f8; border-radius: 3px; padding: 10px; padding-top: 0px; padding-bottom: 0px; } .pseudocode-small { font-size: 16px; } .remark-code { font-size: 68%; } .remark-inline-code { background: #F5F5F5; /* lighter */ /* background: #e7e8e2; /* darker */ border-radius: 3px; padding: 4px; } /* Super and Subscripts */ .super{ vertical-align: super; font-size: 70%; line-height: 1%; } .sub{ vertical-align: sub; font-size: 70%; line-height: 1%; } /* Subheader */ .subheader{ font-weight: 100; font-style: italic; display: block; margin-top: -25px; margin-bottom: 25px; } /* 2/3 left; 1/3 right */ .more-left { float: left; width: 63%; } .less-right { float: right; width: 31%; } .more-right ~ * { clear: both; } /* 9/10 left; 1/10 right */ .left90 { padding-top: 0.7em; float: left; width: 85%; } .right10 { padding-top: 0.7em; float: right; width: 9%; } /* 95% left; 5% right */ .left95 { padding-top: 0.7em; float: left; width: 91%; } .right05 { padding-top: 0.7em; float: right; width: 5%; } .left5 { padding-top: 0.7em; margin-left: 0em; margin-right: -0.4em; float: left; width: 7%; } .left10 { padding-top: 0.7em; margin-left: -0.2em; margin-right: -0.5em; float: left; width: 10%; } .left30 { padding-top: 0.7em; float: left; width: 30%; } .right30 { padding-top: 0.7em; float: right; width: 30%; } .thin-left { padding-top: 0.7em; margin-left: -1em; margin-right: -0.5em; float: left; width: 27.5%; } /* Example */ .ex { font-weight: 300; color: #555F61 !important; font-style: italic; } .col-left { float: left; width: 47%; margin-top: -1em; } .col-right { float: right; width: 47%; margin-top: -1em; } .clear-up { clear: both; margin-top: -1em; } /* Format tables */ table { color: #000000; font-size: 14pt; line-height: 100%; border-top: 1px solid #ffffff !important; border-bottom: 1px solid #ffffff !important; } th, td { background-color: #ffffff; } table th { font-weight: 400; } /* Attention */ .attn { font-weight: 500; color: #e64173 !important; font-family: 'Zilla Slab' !important; } /* Note */ .note { font-weight: 300; font-style: italic; color: #314f4f !important; /* color: #cccccc !important; */ font-family: 'Zilla Slab' !important; } /* Question and answer */ .qa { font-weight: 500; /* color: #314f4f !important; */ color: #e64173 !important; font-family: 'Zilla Slab' !important; } /* Figure Caption */ .caption { font-size: 0.8888889em; line-height: 1.5; margin-top: 1em; color: #6b7280; } </style> <!-- From xaringancolor --> <div style = "position:fixed; visibility: hidden"> $$ \require{color} \definecolor{purple}{rgb}{0.337254901960784, 0.00392156862745098, 0.643137254901961} \definecolor{navy}{rgb}{0.0509803921568627, 0.23921568627451, 0.337254901960784} \definecolor{ruby}{rgb}{0.603921568627451, 0.145098039215686, 0.0823529411764706} \definecolor{alice}{rgb}{0.0627450980392157, 0.470588235294118, 0.584313725490196} \definecolor{daisy}{rgb}{0.92156862745098, 0.788235294117647, 0.266666666666667} \definecolor{coral}{rgb}{0.949019607843137, 0.427450980392157, 0.129411764705882} \definecolor{kelly}{rgb}{0.509803921568627, 0.576470588235294, 0.337254901960784} \definecolor{jet}{rgb}{0.0745098039215686, 0.0823529411764706, 0.0862745098039216} \definecolor{asher}{rgb}{0.333333333333333, 0.372549019607843, 0.380392156862745} \definecolor{slate}{rgb}{0.192156862745098, 0.309803921568627, 0.309803921568627} \definecolor{cranberry}{rgb}{0.901960784313726, 0.254901960784314, 0.450980392156863} $$ </div> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ TeX: { Macros: { purple: ["{\\color{purple}{#1}}", 1], navy: ["{\\color{navy}{#1}}", 1], ruby: ["{\\color{ruby}{#1}}", 1], alice: ["{\\color{alice}{#1}}", 1], daisy: ["{\\color{daisy}{#1}}", 1], coral: ["{\\color{coral}{#1}}", 1], kelly: ["{\\color{kelly}{#1}}", 1], jet: ["{\\color{jet}{#1}}", 1], asher: ["{\\color{asher}{#1}}", 1], slate: ["{\\color{slate}{#1}}", 1], cranberry: ["{\\color{cranberry}{#1}}", 1] }, loader: {load: ['[tex]/color']}, tex: {packages: {'[+]': ['color']}} } }); </script> <style> .purple {color: #5601A4;} .navy {color: #0D3D56;} .ruby {color: #9A2515;} .alice {color: #107895;} .daisy {color: #EBC944;} .coral {color: #F26D21;} .kelly {color: #829356;} .jet {color: #131516;} .asher {color: #555F61;} .slate {color: #314F4F;} .cranberry {color: #E64173;} </style> ## Chapter 26: Regression Inference --- # Introduction Chapter 4 and 5 discussed how scatterplots and lines of best fit show us linear relationships, but there are remaining questions Is there really a linear relationship between x and y, or is the pattern just by chance - Spurious correlations What is the estimated slope that explains how `\(y\)` responds to `\(x\)` .it[in the population]. What is the margin of error for our estimate? - If we use the least-squares line to predict `\(y\)` for a given `\(x\)`, how accurate is that prediction? - In econometrics, you will discuss when you can answer what is the **effect** on `\(y\)` of changing `\(x\)` --- # Regression Review We can model the linear relationship between X and Y by thinking of a conditional expectation: $$ E(Y|X)= a + bX $$ We want estimates for a and b, `\(\hat{a}\)` and `\(\hat{b}\)`, and we find these estimates by minimizing the sum of squared residuals $$ \varepsilon_i = Y_i - \coral{\widehat{Y}_i} \equiv Y_i - (\coral{\hat{a} + \hat{b} X_i}) $$ --- # OLS Estimators We pick the values of `\(\hat{a}\)` and `\(\hat{b}\)` to minimize the sum of least squares, $\sum_{i=1}^n \varepsilon_i^2 $. This yields the Ordinary Least Squares estimators $$ \hat{a}=\bar{Y}-\hat{b}\bar{X} $$ $$ \hat{b}=r_{XY}\frac{s_Y}{s_X} $$ --- # Next Steps This chapter will answer - How can I interpret `\(\hat{a}\)` and `\(\hat{b}\)`? - What conditions are necessary for those interpretations? - Inference from a Regression --- # Interpreting `\(a\)` and `\(b\)` $$ \hat{\coral{\text{Calcification Rate}}} = -12.103 + 0.4615 * \text{Temperature} $$ We can now predict how temperature affects the calcification rate. The `\(R^2\)` will tell us how much of the variation in calcification rate is due to temperature, but it will not tell us whether this relationship is .hi.daisy[statistically significant]. In order for this regression to be meaningful, we must determine whether the results are .hi.daisy[statistically significant] --- # Estimating the Parameters When the conditions for the regression are met.super[1] - The slope `\(\hat{b}\)` of the least-squares line is an unbiased estimator of the population slope `\(b\)` - The intercept `\(\hat{a}\)` of the least-squares line is an unbiased estimator of the population intercept `\(a\)` Now we only need to estimate the remaining parameters, `\(\sigma\)`, the standard deviation of the error term `\(\varepsilon_i\)`. .footnote[.super[1] We will discuss the conditions later] --- # Regression Standard Error Our regression model is: $$ y = a + X b + \varepsilon $$ `\(\varepsilon\)` is the error term that describes why an individual doesn't fall directly on regression line `\(a + X b\)`. We denote the variance of `\(\varepsilon\)` as `\(\sigma^2\)`. The standard deviation, `\(\sigma\)`, describes variability of response variable `\(y\)` about the population regression line ($\pm$). --- # Estimating Std. Dev. of the Error Term The least-squares line estimates the population regression line - The .hi.kelly[residuals] are the deviations of data points from the least-squares line $$ \hat{\varepsilon} \equiv \text{residual} = y - \coral{\hat{y}} $$ Therefore we estimate `\(\sigma\)` by the sample standard deviation of the residuals, known as the .hi.kelly[regression standard error] --- # Regression Standard Error $$ s=\sqrt{\frac{1}{n-2} \sum\text{residual}^2} \equiv \sqrt{\frac{1}{n-2} \sum(y - \coral{\hat{y}})^2} $$ We use `\(s\)` to estimate the standard deviation, `\(\sigma\)`, of responses about the mean given by the population regression line We will use this error to determine whether our predictions are .daisy[statistically significant] --- # Testing the Hypothesis of No Linear Relationship To answer questions about whether associations between two variables are .daisy[statistically significant], we must test a hypothesis about the slope `\(b\)`: `$$H_0: \ b = 0$$` `$$H_1: b \neq 0$$` If we fail to reject `\(H_0\)`: - Regression line with slope 0 is horizontal -- meaning y does not change at all when x changes - `\(H_0\)` says that there is no linear relationship between X and Y If we reject `\(H_0\)`, and accept `\(H_1\)`: - There is some linear relationship between X and Y --- # Null of No Linear Relationship If we fail to reject `\(H_0\)`: - Regression line with slope 0 is horizontal -- meaning `\(y\)` does not change at all when `\(x\)` changes <img src="data:image/png;base64,#ch26_files/figure-html/unnamed-chunk-2-1.svg" width="70%" style="display: block; margin: auto;" /> --- # Population *vs.* sample **Question:** Why do we care about *population vs. sample*? .pull-left[ <img src="data:image/png;base64,#ch26_files/figure-html/pop1-1.svg" style="display: block; margin: auto;" /> .center[**Population**] ] -- .pull-right[ <img src="data:image/png;base64,#ch26_files/figure-html/scatter1-1.svg" style="display: block; margin: auto;" /> .center[**Population relationship**] $$ y_i = 2.53 + 0.57 x_i + u_i $$ $$ y_i = \beta_0 + \beta_1 x_i + u_i $$ ] --- # Population *vs.* sample **Question:** Why do we care about *population vs. sample*? .pull-left[ <img src="data:image/png;base64,#ch26_files/figure-html/sample1-1.svg" style="display: block; margin: auto;" /> .center[**Sample 1:** 30 random individuals] ] .pull-right[ <img src="data:image/png;base64,#ch26_files/figure-html/sample1 scatter-1.svg" style="display: block; margin: auto;" /> .center[ **Population relationship** <br> `\(y_i = 2.53 + 0.57 x_i + u_i\)` **Sample relationship** <br> `\(\hat{y}_i = 2.36 + 0.61 x_i\)` ] ] --- # Population *vs.* sample **Question:** Why do we care about *population vs. sample*? .pull-left[ <img src="data:image/png;base64,#ch26_files/figure-html/sample2-1.svg" style="display: block; margin: auto;" /> .center[**Sample 2:** 30 random individuals] ] .pull-right[ <img src="data:image/png;base64,#ch26_files/figure-html/sample2 scatter-1.svg" style="display: block; margin: auto;" /> .center[ **Population relationship** <br> `\(y_i = 2.53 + 0.57 x_i + u_i\)` **Sample relationship** <br> `\(\hat{y}_i = 2.79 + 0.56 x_i\)` ] ] --- # Population *vs.* sample **Question:** Why do we care about *population vs. sample*? .pull-left[ <img src="data:image/png;base64,#ch26_files/figure-html/sample3-1.svg" style="display: block; margin: auto;" /> .center[**Sample 3:** 30 random individuals] ] .pull-right[ <img src="data:image/png;base64,#ch26_files/figure-html/sample3 scatter-1.svg" style="display: block; margin: auto;" /> .center[ **Population relationship** <br> `\(y_i = 2.53 + 0.57 x_i + u_i\)` **Sample relationship** <br> `\(\hat{y}_i = 3.21 + 0.45 x_i\)` ] ] --- class: clear, center, middle .center[$1,000$ Samples of size `\(30\)`] <img src="data:image/png;base64,#ch26_files/figure-html/simulation scatter-1.svg" width="80%" style="display: block; margin: auto;" /> --- # Population *vs.* sample .pull-left[ <img src="data:image/png;base64,#ch26_files/figure-html/simulation scatter2-1.png" style="display: block; margin: auto;" /> ] .pull-right[ - On **average**, our regression lines match the population line very nicely. - However, **individual lines** (samples) can really miss the mark. - Differences between individual samples and the population lead to **uncertainty** for the econometrician. ] --- # Sampling Distribution of `\(\hat{b}\)` Since `\(\hat{b}\)` is a function of our data, it has a sampling distribution. The sampling distribution of `\(\hat{b}\)` is: $$ \hat{b} \sim N\left(b, \ \frac{\sigma^2}{\sigma_X^2}\right) $$ .footnote[Another instance of the sampling distribution being normally distributed!] `\(\sigma^2\)` is the variance of `\(\varepsilon\)` and `\(\sigma_X^2\)` is the variance of `\(X\)`. --- # Significance Test for Regression Slope To test the hypothesis, `\(H_0: b=0\)`, compute the t-statistic: $$ t_{n-2} = \frac{\hat{b} - 0}{SE_b} $$ Important to note that the degrees of freedom for the t-statistic for testing a regression slope is `\(n-2\)` (we estimate `\(a\)` and `\(s\)`) In this formula, the standard error of the least-squares slope is our estimate at the sampling distribution's standard deviation: $$ SE_{\hat{b}}=\frac{s}{\sqrt{\sum (x-\bar{x}^2)}} $$ --- # Example We fit a least-squares line to the model, `\(\text{Price} = a+b (\text{age})\)` with 28 observations from items sold at antiques show. A summary of the output is below:
Parameter
Parameter Estimate
Std. Error of Estimate
\(\hat{a}\)
27.730
34.840
\(\hat{b}\)
1.893
0.267
Suppose we want to test the hypothesis, `\(H_0: b=0\)` vs. `\(H_1: b \neq 0\)`. The value of this t-statistic is: $$ t_{26} = \frac{b}{SE_b} = \frac{1.893 - 0}{0.267} = 7.09 $$ Using t-table `\(\implies p < 0.001\)` --- # Clicker Question In the previous example we rejected the null hypothesis of `\(b=0\)`, meaning we claim there is sufficient evidence to say there is a linear relationship between age and price sold of items at a antiques road show. What type of error would we have committed if it turned out there was no relationship between age and price? <ol type = "a"> <li>Type I, reject the null even though its true</li> <li>Type II, reject the null even though its true</li> <li>Type I, fail to reject a false null</li> <li>Type II, fail to reject a false null</li> </ol> --- # Additional Example -- Exam Style My budtender friend Eric did a study on marijuana consumption and hot cheeto consumption. He surveyed 25 of his friends and collected the following regression results. Assume `\(\alpha = 0.05\)`
Cheeto Consumption
Estimate
Std. Error
t-statistic
p-value
Intercept
21.0
12.3
Joints Smoked
4.2
1.8
<ol type = "a"> <li> Fill in the rest of the table </li> <li> Is the intercept statistically significant? Why? </li> <li> Is the slope coefficient statistically significant? Why? </li> <li> Interpret slope coefficient </li> </ol> --- # Hypothesis Testing Example .ex[Example:] Regression analysis provides estimates on the relationship between daily wine consumption on risk of breast cancer. The estimated slope was `\(\hat{b} = 0.009\)` with a standard error of `\(SE_{\hat{b}} = 0.001\)` based off 25 observations. We want to test whether these results are strong enough to reject the null hypothesis `$$H_0: b = 0$$` in favor or the alternative hypothesis `$$H_1: b > 0$$` --- # Hypothesis Testing Example So we have `\(\hat{b}\)`=0.009 and `\(SE_{\hat{b}}\)`=0.001. Solving hypothesis test: - Find t-stat $$ t=\frac{0.009}{0.001}=9 $$ - Use t-table to find p-value $$ 25 \text{ observations } \implies t_{n-2} = t_{23} $$ $$ t_{23}^{0.0005} = 3.8 \implies p<0.0005 $$ - Interpret p-value $$ p < 0.0005 \implies p < 0.05 \implies \textbf{Reject `\(H_0\)`} $$ --- # Regression Results ```r # Hourly Earnings ($) on Years of Education summary(lm(wage ~ educ, data = wage1)) ``` ``` #> #> Call: #> lm(formula = wage ~ educ, data = wage1) #> #> Residuals: #> Min 1Q Median 3Q Max #> -5.3396 -2.1501 -0.9674 1.1921 16.6085 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) -0.90485 0.68497 -1.321 0.187 #> educ 0.54136 0.05325 10.167 <2e-16 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> Residual standard error: 3.378 on 524 degrees of freedom #> Multiple R-squared: 0.1648, Adjusted R-squared: 0.1632 #> F-statistic: 103.4 on 1 and 524 DF, p-value: < 2.2e-16 ``` --- # Confidence Interval for Regression Slope The slope, `\(b\)`, of the population regression is usually the most important parameter in a regression problem - The slope is the rate of change of the mean response as the explanatory variable increases - The slope explains how changes in x affect outcome variable y A confidence interval is useful because it shows us <span class="it">how accurate the estimate of `\(b\)` is likely to be</span>. --- # Confidence Interval for Regression Slope A level `\(C\)` confidence interval for the slope `\(b\)` of the population regression line is $$ \hat{b} \pm t^* \cdot SE_{b}, $$ where `\(t^* = t^{\frac{1-C}{2}}_{n-2}\)` --- # Confidence Interval for Regression Slope .ex[Example:] Recall our regression results looking at the relationship of temperature on coral calcification. The estimated slope was `\(\hat{b} = 0.4615\)` and a standard error `\(SE_{\hat{b}} = 0.07394\)`. Note this was based off a sample of 12 observations. 12 observations mean our `\(t_{n-2}\)` distribution has 12-2=10 degrees of freedom and that critical `\(t\)`-stat is `\(2.23\)` when `\((1-C)/2 = 0.05/2 = 0.025\)` -- If we want to construct a 95% confidence interval: $$ \hat{b} \pm t^* SE_{\hat{b} }= 0.4615 \pm (2.23)(0.07394) $$ The 95% confidence interval for population slope `\(b\)` is `\([0.297, 0.626]\)`. --- # Clicker Question A random sample of 19 companies were selected and the relationship between sales (in hundreds of thousands of dollars) and profits (in hundreds of thousands of dollars) was investigated by a regression, `\(profits = a + b \cdot sales\)`. The following results were obtained from statistical software:
Parameter
Parametere Estimate
Std. Error of Estimate
\(\hat{a}\)
-176.6440
61.1600
\(\hat{b}\)
0.0925
0.0075
An approximate 90% confidence interval for the slope `\(b\)` is: <ol type = "a"> <li>\(-176.66\) to \(-176.63\)</li> <li>\(0.079\) to \(0.106\)</li> <li>\(0.071\) to \(0.114\)</li> </ol> --- # Confidence Intervals R will spit out a 95% confidence interval associated with slope estimates with `confint`: ```r # Hourly Earnings ($) on Years of Education confint(lm(wage ~ educ, data = wage1)) ``` ``` #> 2.5 % 97.5 % #> (Intercept) -2.2504719 0.4407687 #> educ 0.4367534 0.6459651 ``` 95% confident that an additional year of schooling increases average hourly earnings between $0.44 and $0.65 --- # Significance and Margin of Error Conducting a hypothesis test on `\(\hat{b}\)` tells you about the .hi.purple[significance] of your result - `\(p\)`-value `\(< \alpha\)`, we can say our coefficient is statistically different from zero A confidence interval says something about the precision of the coefficient - What are the ranges of coefficient values we expect the true-value to be in between - Confidence interval is also the only points you will fail to reject the null. --- # Significance and Margin of Error ``` #> #> Call: #> lm(formula = wage ~ educ, data = wage1) #> #> Residuals: #> Min 1Q Median 3Q Max #> -5.3396 -2.1501 -0.9674 1.1921 16.6085 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) -0.90485 0.68497 -1.321 0.187 #> educ 0.54136 0.05325 10.167 <2e-16 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> Residual standard error: 3.378 on 524 degrees of freedom #> Multiple R-squared: 0.1648, Adjusted R-squared: 0.1632 #> F-statistic: 103.4 on 1 and 524 DF, p-value: < 2.2e-16 ``` Do we reject null that education has no effect on wage? --- # Categorical Variable inside Regression In that previous example, the explanatory variable was categorical. Let's see how that changes interpretation. ```r # Hourly Earnings ($) on HS Degree summary(lm(wage ~ hs_deg, data = wage1)) ``` ``` #> #> Call: #> lm(formula = wage ~ hs_deg, data = wage1) #> #> Residuals: #> Min 1Q Median 3Q Max #> -5.8865 -2.4165 -0.9267 1.1734 18.5635 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 4.0567 0.3309 12.258 < 2e-16 *** #> hs_deg 2.3598 0.3748 6.296 6.48e-10 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> Residual standard error: 3.564 on 524 degrees of freedom #> Multiple R-squared: 0.07032, Adjusted R-squared: 0.06854 #> F-statistic: 39.63 on 1 and 524 DF, p-value: 6.485e-10 ``` --- # Categorical Variable inside Regression This regression implies the relationship between HS Degree and hourly earnings is: $$ \coral{\hat{Income}} = \$4.06 + \$2.36 \cdot \text{HS Degree} $$ The takeaways here would be: - Without a HS degree, predicted wage is $4.06 - With a PhD, predicted wage is $4.06 + $2.36 The coefficient on an indicator represents the *difference* in averages of `\(Y\)` between the `\(= 0\)` and `\(= 1\)` groups. --- # Conditions for Regression Inference Say we have `\(n\)` observations regarding explanatory variable `\(x\)` and response variable `\(y\)`. - The mean response `\(E(Y | X)\)` has a .hi.purple[straight-line relationship] with x, given by a population regression line `$$E(Y|X) = a + b X$$` - For any fixed value of `\(x\)`, the response variable `\(y\)` varies according to a normal distribution - Repeated responses `\(y\)` are independent of each other - The .hi.daisy[standard deviation] of `\(\varepsilon\)`, `\(\sigma\)`, is the same for all values of x. --- # Intuition about Conditions <span class="it">The mean response `\(E(Y \ \vert \ X)\)` has a .hi.purple[straight-line relationship] with `\(x\)`, given by a population regression line</span> - In practice, we observe `\(y\)` for many different values of `\(x\)`. Eventually we see an overall linear pattern formed by points scattered about the population line. --- # Intuition about Conditions <span class="it">For any fixed value of `\(x\)`, the response variable `\(y\)` varies according to a normal distribution</span> - We cannot observe the entire population regression line. The values of `\(y\)` that we do observe vary about their means according to a normal distribution. If we hold x constant and take many observations of y, the Normal pattern will eventually appear in a histogram. --- # Intuition about Conditions <span class="it">The .hi.purple[standard deviation] of `\(\varepsilon\)`, `\(\sigma\)`, is the same for all values of x. The value of `\(\sigma\)` is unknown.</span> - The standard deviation determines whether the points fall close to the population regression line (small `\(\sigma\)`) or are widely scattered (large `\(\sigma\)`) - If `\(\sigma\)` changes depending on `\(x\)`, then our sample distribution would be wrong. --- # Intuition about Conditions <img src="data:image/png;base64,#conditions.png" width="90%" style="display: block; margin: auto;" /> - For each possible value of `\(x\)`, the mean of the responses moves along the population regression line - For a fixed `\(x\)`, the responses `\(y\)` follow a normal distribution with std. dev `\(\sigma\)` - The normal curve shows how `\(y\)` will vary when `\(x\)` is held constant --- # Checking Conditions for Inference Remember, all of this discussion about inferences hinges on the data meeting certain conditions. - The relationship is linear in the population - The response varies normally about the regression line - Observations are independent - The standard deviation of the responses is the same for all values of x --- # Checking Conditions for Inference In order to check these conditions, it can be helpful to look at a residual plot. A .hi.purple[residual plot] plots the residuals against the explanatory variable `\(x\)`, with a horizontal line at the "residual =0" position. The "residual =0" line represents the position of the least-squares line in the scatterplot of y against `\(x\)`. <div class = "pull-left"> <h3 style="margin-bottom: 5px;"> Regression Plot </h3> <img src="data:image/png;base64,#scatter.png" width="100%" style="display: block; margin: auto;" /> </div> <div class = "pull-right"> <h3 style="margin-bottom: 5px;"> Residual Plot </h3> <img src="data:image/png;base64,#resid.png" width="100%" style="display: block; margin: auto;" /> </div> --- # Checking Conditions for Inference - .hi[The relationship is linear]. Look for curved patterns or other deviations from an overall straight line pattern in residual plot - .hi[The response varies normally about regression line]. Check for departures from normality in your stemplot or histogram of residuals. - .hi[Observations are independent]. Signs of dependence in the residual plot are subtle, so usually use common sense. - .hi[Standard deviation of responses is same for all values of] `\(x\)`. Look at the scatter of residuals above and below the "residual =0" line. The scatter should be roughly the same from one end to the other.