2024-2-4

── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

Attaching package: 'plotly'


The following object is masked from 'package:ggplot2':

    last_plot


The following object is masked from 'package:stats':

    filter


The following object is masked from 'package:graphics':

    layout

Linear Regression

Linear regression is a statistical method used to predict the values of variables based on the values of different variables. Typically, you would use a sample of data where you know the independent and dependent variables to find the equation of a straight line that could be used to predict the dependent variable value given an independent variable’s value.

The equation of this line would be in the usual form that straight lines follow: \(y=mx+b\)

Equation for Linear Regression

Though the equation for linear regression is simply a straight line, it is often represented by: \(Y_i = \beta_0 + \beta_1 X_i + \epsilon_i\)

Slide 3 with R Output

summary(ChickWeight)
     weight           Time           Chick     Diet   
 Min.   : 35.0   Min.   : 0.00   13     : 12   1:220  
 1st Qu.: 63.0   1st Qu.: 4.00   9      : 12   2:120  
 Median :103.0   Median :10.00   20     : 12   3:120  
 Mean   :121.8   Mean   :10.72   10     : 12   4:118  
 3rd Qu.:163.8   3rd Qu.:16.00   17     : 12          
 Max.   :373.0   Max.   :21.00   19     : 12          
                                 (Other):506          

Slide 4 with Plot - plotly

Slide 5 - ggplot 1

Final Weight of the Chicks

The box plot in the previous slide shows that the chicks who ate diet 3 had the highest final weight, followed by the chicks who ate diets 4, 3 and 1.. The chicks who ate diet 1 had a substantially lower median weight than those who ate diet 3, with a median weight of more that 100 fewer.

Slide 7 - ggplot 2

`geom_smooth()` using formula = 'y ~ x'

Swiss Dataset

The plot on the previous slide shows that there is a negative correlation between fertility and education beyonnd primary school in the swiss dataset.