-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/UBC-STAT/stat-301
- Loading branch information
Showing
8 changed files
with
38,606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
week,fat | ||
11,0.72 | ||
12,0.68 | ||
13,0.65 | ||
14,0.64 | ||
15,0.57 | ||
16,0.48 | ||
17,0.46 | ||
18,0.45 | ||
19,0.31 | ||
20,0.33 | ||
21,0.36 | ||
22,0.3 | ||
23,0.26 | ||
24,0.34 | ||
25,0.29 | ||
26,0.31 | ||
27,0.29 | ||
28,0.2 | ||
29,0.15 | ||
30,0.18 | ||
31,0.11 | ||
32,0.07 | ||
33,0.06 | ||
34,0.01 | ||
35,0.01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
week,fat | ||
1,0.31 | ||
2,0.39 | ||
3,0.5 | ||
4,0.58 | ||
5,0.59 | ||
6,0.64 | ||
7,0.68 | ||
8,0.66 | ||
9,0.67 | ||
10,0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,316 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 68, | ||
"id": "8e8a5403-1079-49aa-8063-cb244bb6eabb", | ||
"metadata": { | ||
"tags": [], | ||
"vscode": { | ||
"languageId": "r" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"library(tidyverse)\n", | ||
"library(palmerpenguins)\n", | ||
"library(broom)\n", | ||
"library(modelr)\n", | ||
"\n", | ||
"options(repr.plot.width = 10, repr.plot.height = 5) " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f5c616aa-c4ea-4be3-916d-e4663056e601", | ||
"metadata": {}, | ||
"source": [ | ||
"# Linear Regression Model\n", | ||
"**Lecture 2 - Demo**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "8181e27f-9fdd-4501-8227-c742f18177fd", | ||
"metadata": { | ||
"tags": [], | ||
"vscode": { | ||
"languageId": "r" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<table class=\"dataframe\">\n", | ||
"<caption>A tibble: 5 × 7</caption>\n", | ||
"<thead>\n", | ||
"\t<tr><th scope=col>species</th><th scope=col>island</th><th scope=col>bill_length_mm</th><th scope=col>bill_depth_mm</th><th scope=col>flipper_length_mm</th><th scope=col>body_mass_g</th><th scope=col>sex</th></tr>\n", | ||
"\t<tr><th scope=col><fct></th><th scope=col><fct></th><th scope=col><dbl></th><th scope=col><dbl></th><th scope=col><int></th><th scope=col><int></th><th scope=col><fct></th></tr>\n", | ||
"</thead>\n", | ||
"<tbody>\n", | ||
"\t<tr><td>Adelie </td><td>Dream </td><td>41.5</td><td>18.5</td><td>201</td><td>4000</td><td>male </td></tr>\n", | ||
"\t<tr><td>Gentoo </td><td>Biscoe</td><td>45.0</td><td>15.4</td><td>220</td><td>5050</td><td>male </td></tr>\n", | ||
"\t<tr><td>Gentoo </td><td>Biscoe</td><td>48.5</td><td>14.1</td><td>220</td><td>5300</td><td>male </td></tr>\n", | ||
"\t<tr><td>Chinstrap</td><td>Dream </td><td>50.3</td><td>20.0</td><td>197</td><td>3300</td><td>male </td></tr>\n", | ||
"\t<tr><td>Chinstrap</td><td>Dream </td><td>45.7</td><td>17.0</td><td>195</td><td>3650</td><td>female</td></tr>\n", | ||
"</tbody>\n", | ||
"</table>\n" | ||
], | ||
"text/latex": [ | ||
"A tibble: 5 × 7\n", | ||
"\\begin{tabular}{lllllll}\n", | ||
" species & island & bill\\_length\\_mm & bill\\_depth\\_mm & flipper\\_length\\_mm & body\\_mass\\_g & sex\\\\\n", | ||
" <fct> & <fct> & <dbl> & <dbl> & <int> & <int> & <fct>\\\\\n", | ||
"\\hline\n", | ||
"\t Adelie & Dream & 41.5 & 18.5 & 201 & 4000 & male \\\\\n", | ||
"\t Gentoo & Biscoe & 45.0 & 15.4 & 220 & 5050 & male \\\\\n", | ||
"\t Gentoo & Biscoe & 48.5 & 14.1 & 220 & 5300 & male \\\\\n", | ||
"\t Chinstrap & Dream & 50.3 & 20.0 & 197 & 3300 & male \\\\\n", | ||
"\t Chinstrap & Dream & 45.7 & 17.0 & 195 & 3650 & female\\\\\n", | ||
"\\end{tabular}\n" | ||
], | ||
"text/markdown": [ | ||
"\n", | ||
"A tibble: 5 × 7\n", | ||
"\n", | ||
"| species <fct> | island <fct> | bill_length_mm <dbl> | bill_depth_mm <dbl> | flipper_length_mm <int> | body_mass_g <int> | sex <fct> |\n", | ||
"|---|---|---|---|---|---|---|\n", | ||
"| Adelie | Dream | 41.5 | 18.5 | 201 | 4000 | male |\n", | ||
"| Gentoo | Biscoe | 45.0 | 15.4 | 220 | 5050 | male |\n", | ||
"| Gentoo | Biscoe | 48.5 | 14.1 | 220 | 5300 | male |\n", | ||
"| Chinstrap | Dream | 50.3 | 20.0 | 197 | 3300 | male |\n", | ||
"| Chinstrap | Dream | 45.7 | 17.0 | 195 | 3650 | female |\n", | ||
"\n" | ||
], | ||
"text/plain": [ | ||
" species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g\n", | ||
"1 Adelie Dream 41.5 18.5 201 4000 \n", | ||
"2 Gentoo Biscoe 45.0 15.4 220 5050 \n", | ||
"3 Gentoo Biscoe 48.5 14.1 220 5300 \n", | ||
"4 Chinstrap Dream 50.3 20.0 197 3300 \n", | ||
"5 Chinstrap Dream 45.7 17.0 195 3650 \n", | ||
" sex \n", | ||
"1 male \n", | ||
"2 male \n", | ||
"3 male \n", | ||
"4 male \n", | ||
"5 female" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"penguins_clean <-\n", | ||
" penguins %>%\n", | ||
" drop_na() %>%\n", | ||
" select(-year)\n", | ||
"\n", | ||
"penguins_clean %>%\n", | ||
" slice_sample(n = 5)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "40a2fde9-b2db-4fcf-999b-4585c75f5f5b", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1. **One Binary Covariate**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c82b1db7-9a74-4976-83f8-c85169f98e35", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### 1.1 **What the model looks like**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8a40c2ac-d389-45c8-8825-ecd80c4cab44", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "15a094ea-d0ad-421d-bcf0-113a97d638e9", | ||
"metadata": {}, | ||
"source": [ | ||
"#### 1.1.1 **Dummy Variables**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f36ab118-e5b9-48df-b697-489afe2b78dc", | ||
"metadata": {}, | ||
"source": [ | ||
"### 1.2 **Fitting using R**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c0fdb706-15c2-4871-9198-c3d2f2857f37", | ||
"metadata": {}, | ||
"source": [ | ||
"### 1.3 **Equivalent to t-test from STAT 201**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "89b40ac1-f9f6-4728-a20c-07360837fd02", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## 2. **Categorical covariate with more than 2 categories**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2fef3c0d-f90e-4f3c-b594-f179da1ccba5", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### 2.1 **What the model looks like**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "97901247-9cbc-4abe-a438-da9554035c80", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e6f0eec5-f58f-42ae-9397-003536a00823", | ||
"metadata": {}, | ||
"source": [ | ||
"#### 2.1.1 **Dummy Variables**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "60b7b0fe-a14a-419b-94e2-59595fc0b54d", | ||
"metadata": { | ||
"vscode": { | ||
"languageId": "r" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "afb602ac-8cc7-4e25-87a8-34ebc45d7278", | ||
"metadata": {}, | ||
"source": [ | ||
"### 2.2 **Fitting using R**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e3b1301f-b04e-437f-a1fc-633358771e26", | ||
"metadata": {}, | ||
"source": [ | ||
"### 2.3 Difference in means?" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "73db7e2c-c6b4-4cca-928c-f9d3ac804ed4", | ||
"metadata": {}, | ||
"source": [ | ||
"## 3. One Categorical and One Numerical " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "22b43d4e-33da-4311-9216-cb6d527f7944", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### 3.1 **What the model looks like**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7e56be67-9118-4315-a458-a52c953dc424", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1aeee946-ce28-4cdb-8494-9da851c810de", | ||
"metadata": {}, | ||
"source": [ | ||
"### 3.2 **Fitting using R**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "650a6531-7f9e-485b-a6eb-68676f0e0708", | ||
"metadata": {}, | ||
"source": [ | ||
"In this model, the difference in the means between the groups do not depend on the `flipper_length_mm`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2f2cc1c1-0538-4481-be8f-a60d4767dabc", | ||
"metadata": {}, | ||
"source": [ | ||
"## 4. **MLR with interaction**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "221224d5-c144-4afb-93e9-3a9a0cc5ee39", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"### 4.1 **What the model looks like**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "81bcd409-3ebe-433a-93d5-e1e15fdb2535", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6b0371d2-0d89-4f9b-bfe0-a6c0d2357b5a", | ||
"metadata": {}, | ||
"source": [ | ||
"### 4.2 **Fitting using R**" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "R", | ||
"language": "R", | ||
"name": "ir" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "r", | ||
"file_extension": ".r", | ||
"mimetype": "text/x-r-source", | ||
"name": "R", | ||
"pygments_lexer": "r", | ||
"version": "4.2.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.