This is an example markdown document, using the iris
data set. This data set is built into RStudio and can be called up
with
data <- iris
We can view the first 6 rows of the data with:
head(data)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
The iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica.
The code below will create a scatterplot of Sepal.Length
versus Sepal.Width for each of the three species:
library(tidyverse)
ggplot(data, aes(Sepal.Length, Sepal.Width)) +
geom_point() +
facet_wrap(~Species)
The code below shows how to construct a linear regression model for Sepal.Width based on the variables within the data set:
model <- lm(Sepal.Width ~ Sepal.Length + Petal.Length + Petal.Width + Species, data)
The summary function is then used to call up the model results
summary(model)
##
## Call:
## lm(formula = Sepal.Width ~ Sepal.Length + Petal.Length + Petal.Width +
## Species, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.00102 -0.14786 0.00441 0.18544 0.69719
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.65716 0.25595 6.475 1.40e-09 ***
## Sepal.Length 0.37777 0.06557 5.761 4.87e-08 ***
## Petal.Length -0.18757 0.08349 -2.246 0.0262 *
## Petal.Width 0.62571 0.12338 5.072 1.20e-06 ***
## Speciesversicolor -1.16029 0.19329 -6.003 1.50e-08 ***
## Speciesvirginica -1.39825 0.27715 -5.045 1.34e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2678 on 144 degrees of freedom
## Multiple R-squared: 0.6352, Adjusted R-squared: 0.6225
## F-statistic: 50.14 on 5 and 144 DF, p-value: < 2.2e-16