Written response for 2A

gibbons <- c(1.3, 2.4, 2.5, 2.6, 3.8, 4.1, 4.3, 4.4, 4.5, 4.6, 5.0, 5.3, 5.4, 5.5, 6.1, 6.3, 6.7, 6.8, 6.9, 7, 7.2, 9.4, 9.8, 9.9, 10, 10.3, 10.8, 11.5, 11.7, 11.9)

length(gibbons)
## [1] 30
class(gibbons)
## [1] "numeric"

Written response for 2B: Since “gibbons” is a vector with integers and non-integers it is classified as numeric data.

2C

figs <- rnorm(n = 30, mean = 8 * gibbons, sd = 4)

Written response for 2D: When asking for “sort(gibbons)” it gives all of the values of the population density of gibbons from lowest to highest. When asking for “sort(gibbons, decreasing = TRUE)” it gives all the values of the population density of gibbons from highest to lowest.

sort(gibbons)
##  [1]  1.3  2.4  2.5  2.6  3.8  4.1  4.3  4.4  4.5  4.6  5.0  5.3  5.4  5.5  6.1
## [16]  6.3  6.7  6.8  6.9  7.0  7.2  9.4  9.8  9.9 10.0 10.3 10.8 11.5 11.7 11.9
sort(gibbons, decreasing = TRUE)
##  [1] 11.9 11.7 11.5 10.8 10.3 10.0  9.9  9.8  9.4  7.2  7.0  6.9  6.8  6.7  6.3
## [16]  6.1  5.5  5.4  5.3  5.0  4.6  4.5  4.4  4.3  4.1  3.8  2.6  2.5  2.4  1.3

2E:

mean_gibbons <- mean(gibbons)
abovemean_gibbons <- gibbons[gibbons > mean_gibbons]
print(abovemean_gibbons)
##  [1]  6.7  6.8  6.9  7.0  7.2  9.4  9.8  9.9 10.0 10.3 10.8 11.5 11.7 11.9
length(abovemean_gibbons)
## [1] 14

Written response for 2E: There are 14 gibbons that are greater than the mean of 6.6. The values of the gibbons are 6.7, 6.8, 6.9, 7.0, 7.2, 9.4, 9.8, 9.9, 10.0, 10.3, 10.8, 11.5, 11.7, and 11.9.

2F:

hist(figs, xlab = "Fig density",
     main = "Distribution of fig densities",
     col = "darkgreen")

hist(gibbons, xlab = "Gibbon density",
     main = "Distribution of gibbon densities",
     col = "orange")

hist(gibbons, xlab = "Gibbon density",
     main = "Distribution of gibbon densities",
     col = "orange",
     breaks = 3)

hist(gibbons, xlab = "Gibbon density",
     main = "Distribution of gibbon densities",
     col = "orange",
     breaks = 12)

Written response for 2F: The command “breaks” changes the number of histogram bins which increases or decreases the number of bars on the histogram. This difference can be seen between the graphs with “breaks = 3” and “breaks = 12”. There are many more bars in the “breaks = 12” making it easier to read and less in “breaks = 3” which is more difficult to read.

hist(gibbons, xlab = "Gibbon density",
     main = "Distribution of gibbon densities",
     col = "orange",
     breaks = 12)

curve(dnorm(x, mean = mean(gibbons), sd = sd(gibbons)),
      from = min(gibbons),
      to = max(gibbons),
      col = "blue",
      add = TRUE)

2H:

###Scatterplot of population density

plot(gibbons, figs)

mean_figs <- mean(figs)
print(mean_figs)
## [1] 53.18929
###Scatterplot with solid blue triangles
plot(gibbons, figs,
     pch = 6,
     col = "blue",
     cex = 1.5)
abline(h = mean_figs, lty = 2, col = "red")

2I:

lm(gibbons ~ figs)
## 
## Call:
## lm(formula = gibbons ~ figs)
## 
## Coefficients:
## (Intercept)         figs  
##     0.08979      0.12240
ml <- lm(gibbons ~ figs)
summary(ml)
## 
## Call:
## lm(formula = gibbons ~ figs)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.89499 -0.20790 -0.02916  0.25185  0.99685 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.089795   0.196253   0.458    0.651    
## figs        0.122397   0.003358  36.448   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4454 on 28 degrees of freedom
## Multiple R-squared:  0.9794, Adjusted R-squared:  0.9786 
## F-statistic:  1328 on 1 and 28 DF,  p-value: < 2.2e-16

Written response for 2I: P-value is less than 0.05 so we are 95% confident to reject the null hypothesis that there is no correlation. Consequently, we are 95% confident that there is a positive correlation between fig and gibbon density.

2J:

plot(figs, gibbons,
    pch = 19,
    col = "black",
    xlab = "Fig density",
    ylab = "Gibbon density",
    main = "Gibbon density vs. Fig density")
abline(ml, col = "red")

Written response for 3A: The code isn’t running since “Gibbons” is capitalized, it should just be “gibbons”. The correct code is”

mean(gibbons)
## [1] 6.6

Written response for 3B: For this one, the “darkgreen” is not in parenthesis and it should be. The correct code is:

plot(gibbons ~ figs, 
     xlab = "Fig density", 
     ylab = "Gibbon density",
     main = "Gibbon density vs. fig stem density", 
     col = "darkgreen")

Written response for 3C: The mistake in this one is using the variable “h” instead of “v” since figs is on the vertical axis. The correct code is:

hist(figs)
abline(v = mean(figs))

Written response for 3D: This code is not running because the third line down is missing a comma. The code should read:

plot(gibbons ~ figs, 
     xlab = "Fig density", 
     ylab = "Gibbon density",
     main = "Gibbon density vs. fig stem density")

Written response for 3E: This code is not running because it is not possible to count down from 10 to 9 with a positive 0.1. The code should read:

seq(10, 9, -0.1)
##  [1] 10.0  9.9  9.8  9.7  9.6  9.5  9.4  9.3  9.2  9.1  9.0