id <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36)
segment <- c(23, 30, 54, 28, 31, 29, 34, 35, 30, 27, 21, 43, 51, 35, 51, 49, 35, 24, 26, 29, 21, 29, 37, 27, 28, 33, 33, 23, 37, 27, 40, 48, 41, 20, 30, 57)
dendritic <- data.frame(id, segment)
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.2 v dplyr 1.0.0
## v tidyr 1.1.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
ggplot(data= dendritic, aes(segment)) +
geom_dotplot(dotsize = 0.5) +
scale_y_continuous(NULL, breaks = NULL)
## `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
### Histogram of prior example
ggplot(data= dendritic, aes(segment)) +
geom_histogram(bins = 12)
segment <- c(23, 30, 54, 28, 31, 29, 34, 35, 30, 27, 21, 43, 51, 35, 51, 49, 35, 24, 26, 29, 21, 29, 37, 27, 28, 33, 33, 23, 37, 27, 40, 48, 41, 20, 30, 57)
hist(segment)
avg <-mean(segment)
med <- median(segment)
abline(v = avg, col = "red")
abline(v = med, col = "blue")
10 aliquots of identical size were taken from the same culture of the bacterium E.coli. The number of bacteria resistant to a certain virus was determined
aliquots <- c(14, 15, 13, 21, 15, 14, 26, 16, 20, 13)
mean(aliquots)
## [1] 16.7
median(aliquots)
## [1] 15
hist(aliquots, breaks = 3, main = "Number of aliquots with virus resistant bacteria")
Study of milk production in sheep (for making cheese) measures 3-month milk yield for each of 11 ewes (in litres)
id <- c(1,2,3,4,5,6,7,8,9,10,11)
sheep_milk <- c(56.5, 89.8, 110.1, 65.6, 63.7, 82.6, 75.1, 91.5, 102.9, 44.4, 108.1)
df <- data.frame(id, sheep_milk)
mean(sheep_milk)
## [1] 80.93636
median(sheep_milk)
## [1] 82.6
boxplot(sheep_milk, main = "3-Month Milk Yield for 11 Ewes (in litres", horizontal = TRUE)
id <- c(1,2,3,4,5,6,7,8,9,10,11)
sheep_milk <- c(56.5, 89.8, 110.1, 65.6, 63.7, 82.6, 75.1, 91.5, 102.9, 44.4, 108.1)
df <- data.frame(id, sheep_milk)
ggplot(data = df, aes(id, sheep_milk)) +
geom_boxplot()
## Warning: Continuous x aesthetic -- did you forget aes(group=...)?
summary(sheep_milk)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 44.40 64.65 82.60 80.94 97.20 110.10
df %>%
summarize(iqr_sheep = IQR(sheep_milk))
## iqr_sheep
## 1 32.55
Rowan (Sorbus aucuparia) tree grows in a wide range of altitudes. To study how the tree adapts to varying habitats, twigs with buds from 12 trees were collected from different altitudes
par(mfrow=c(1,1))
rowan_x <- c(90, 230, 240, 260, 330, 400, 410, 550, 590, 610, 700, 790)
rowan_y <- c(0.11, 0.20, 0.13, 0.15, 0.18, 0.16, 0.23, 0.18, 0.23, 0.26, 0.32, 0.37)
rowan_lm <- lm(rowan_y ~ rowan_x)
rowan_lm
##
## Call:
## lm(formula = rowan_y ~ rowan_x)
##
## Coefficients:
## (Intercept) rowan_x
## 0.0719605 0.0003186
plot (rowan_x, rowan_y, abline(rowan_lm), xlab = "Rowan X (m)",
main = "Rowan tree respiration rates versus altitude of origin")
Alternatively, run code from the package “ggplot2” to install it for the first time, use the intall code: install.packages(“ggplot2”)
Then you must call the library(ggplot2) every time you want to use it
library(ggplot2)
qplot(rowan_x, rowan_y)
qplot(rowan_x, rowan_y) + geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'
qplot(rowan_x, rowan_y) + geom_smooth(method = "loess")
## `geom_smooth()` using formula 'y ~ x'
#2.5.4 # side by side boxplots of exercise by gender
sex <- c("m","m","m","m","m","m","m","m","m","m","m","m","f","f","f","f","f","f","f","f","f","f","f","f","f")
ex_hours <- c(6,0,2,1,2,4.5,8,3,17,4.5,4,5,5,13,3,2,6,14,3,1,1.5,1.5,3,8,4)
df2 <- data.frame(sex, ex_hours)
length(sex)
## [1] 25
length(ex_hours)
## [1] 25
ggplot(df2, aes(sex, ex_hours, color = sex)) +
geom_boxplot()
ggplot(df2, aes(sex, ex_hours, fill = sex)) +
geom_boxplot()
Read in the document with the read.csv or read_csv command (you will need tidyverse for read_csv)
exerc <- read_csv("C:/Users/MCuser/Dropbox/Rachel/MontColl/Math217/ExerciseSolutions/2_5_4_exercise.csv")
## Parsed with column specification:
## cols(
## gender = col_character(),
## exercise_hours = col_double()
## )
boxplot(exerc$exercise_hours ~ exerc$gender)
#2.6.5
birch <- c(1.45, 1.19, 1.05, 1.07)
mean(birch)
## [1] 1.19
sd(birch)
## [1] 0.184029
#2.6.6
bp_change <- c(-13, -29, -7, 2, -10, -43, 4, 15, -13, -30)
mean(bp_change)
## [1] -12.4
sd(bp_change)
## [1] 17.58914
#2.6.8
lizard <- c(18.4, 22.2, 26.4, 27.5, 28.7, 30.6, 32.9, 32.9,
34, 34.8, 37.5, 42.1, 45.5, 45.5)
summary(lizard)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.40 27.80 32.90 32.79 36.83 45.50
range(lizard)
## [1] 18.4 45.5
#2.S.7
epilepsy <- c(5, 0, 9, 6, 0, 0, 5, 0, 6, 1, 5, 0, 0, 0, 0, 7, 0, 0, 4, 7)
summary(epilepsy)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 0.00 0.50 2.75 5.25 9.00
hist(epilepsy)
#2.S.13
pony <- c(35, 19, 33, 34, 17, 26, 16, 40, 28, 30, 23, 12, 27, 33, 22, 31, 28,
28, 35, 23, 23, 19, 29)
summary(pony)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12.00 22.50 28.00 26.57 32.00 40.00
boxplot(pony, main = "Nerve cell counts in pony intestines")