Introduction to Data Science with R

Author

Jon McCurdy

Published

May 3, 2025

Preface

  • Understand the basics of regression analysis.
  • Learn how to interpret p-values and confidence intervals.
  • Apply regression in R to a real dataset.

This is a Quarto book.

To learn more about Quarto books visit https://quarto.org/docs/books.

1 + 1
[1] 2
3+2
[1] 5
linear_model <- lm(Sepal.Length ~ Sepal.Width, data=iris)
summary(linear_model)

Call:
lm(formula = Sepal.Length ~ Sepal.Width, data = iris)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.5561 -0.6333 -0.1120  0.5579  2.2226 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   6.5262     0.4789   13.63   <2e-16 ***
Sepal.Width  -0.2234     0.1551   -1.44    0.152    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.8251 on 148 degrees of freedom
Multiple R-squared:  0.01382,   Adjusted R-squared:  0.007159 
F-statistic: 2.074 on 1 and 148 DF,  p-value: 0.1519

Watch this video

We can add a video fairly easily with the following code (modestbranding reduces logo and rel=0 does not suggest other channels when paused)

(https://quarto.org/docs/authoring/videos.html)

Callout Boxes

We can make callout boxes for note, warning, important, tip, and caution

(https://quarto.org/docs/authoring/callouts.html)

Note

Note that there are five types of callouts, including: note, warning, important, tip, and caution.

Tip with Title

This is an example of a callout with a title.

This is an example of a ‘folded’ caution callout that can be expanded by the user. You can use collapse="true" to collapse it by default or collapse="false" to make a collapsible callout that is expanded by default.

Tip with Title

This is a callout with a title.

Sample Questions for Students

Try it Out

What is the output of mean(c(1, 2, 3, 4, 5)) in R?

The output is 3. This is because it calculates the arithmetic mean:
(1 + 2 + 3 + 4 + 5) / 5 = 15 / 5 = 3.

Creating Problems for Students to Try

Try it Out

What is the output of mean(c(1, 2, 3, 4, 5)) in R?

Click to see the solution

The output is 3. This is because it calculates the arithmetic mean:
(1 + 2 + 3 + 4 + 5) / 5 = 15 / 5 = 3.

Creating Quiz Questions for Students

(https://web.mat.upc.edu/joaquim.puig/posts/webexercises-quiz/)

  • Numeric questions How much is 2+3?
  • Multiple Choice Which is the capital city of Barbados?
  • True or False Quarto is very cool .
  • Fill in the Blank What is the letter after D? .
  • Type a vowel:
  • Which function will help me find standard deviation for the code: (c(1,4,7,8,4))

Testing 123