#Exercise 2
##A
gibbons<- c(1,2.3,4.5,6.7,8.9,9,9.9,8.7,6.5,4.4,3,5,7,12,2,3,4,5,7,8,5.5,7.7,8.6,7.5,6.5,7,8,6,4,2)
length(gibbons)## [1] 30
## num [1:30] 1 2.3 4.5 6.7 8.9 9 9.9 8.7 6.5 4.4 ...
Gibbons is numerical data
## [1] 1.0 2.0 2.0 2.3 3.0 3.0 4.0 4.0 4.4 4.5 5.0 5.0 5.5 6.0 6.5
## [16] 6.5 6.7 7.0 7.0 7.0 7.5 7.7 8.0 8.0 8.6 8.7 8.9 9.0 9.9 12.0
## [1] 12.0 9.9 9.0 8.9 8.7 8.6 8.0 8.0 7.7 7.5 7.0 7.0 7.0 6.7 6.5
## [16] 6.5 6.0 5.5 5.0 5.0 4.5 4.4 4.0 4.0 3.0 3.0 2.3 2.0 2.0 1.0
The sort() function reported the data by increasing order with the smallest value first. The sort(x,decreasing) command sorted the data by decreasing order with the highest number first.
## num [1:16] 6.7 8.9 9 9.9 8.7 6.5 7 12 7 8 ...
##F
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=7 )
hist(gibbons, xlab = "Gibbon density",
main = "Distribution of Gibbon densities",
col = "orange", breaks=8 )This changes the number of bins in the histogram and spreads the data out
##G
hist(gibbons, xlab = "Gibbon density",
main = "Distribution of Gibbon densities",
col = "orange", breaks=10, prob=TRUE)
curve(dnorm(x, sd=0.5*(mean(gibbons))) , from=0, to=12, col="red", add=TRUE)plot(gibbons~figs, xlab = "Fig density",ylab="Gibbon Density", pch=24, col="blue", cex= 3, bg="blue")
abline(h=mean(gibbons))##
## Call:
## lm(formula = gibbons ~ figs)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.07598 -0.34411 0.08961 0.26260 0.87062
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.363441 0.218076 1.667 0.107
## figs 0.118593 0.004163 28.487 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4924 on 28 degrees of freedom
## Multiple R-squared: 0.9666, Adjusted R-squared: 0.9655
## F-statistic: 811.5 on 1 and 28 DF, p-value: < 2.2e-16
The output of the linear model shoes that figs density is highly correlated to gibbon density as shown by the p-value of <2e-16.
##J
plot(gibbons,figs,xlab = "Fig density",ylab="Gibbon Density", pch=21, col="purple", cex= 2, bg="lavender" )
abline(gf1)## [1] 6.023333
The issue with the original code is that it was incorrectly capitalized.
##B
plot(gibbons ~ figs,
xlab = "Fig density",
ylab = "Gibbon density",
main = "Gibbon density vs. fig stem density",
col = "darkgreen")
The issue here was that darkgreen was not in quotation marks.
This code runs correctly
##D
plot(gibbons ~ figs,
xlab = "Fig density",
ylab = "Gibbon density",
main = "Gibbon density vs. fig stem density")
The issue is that there was not a comma after ylab=“Gibbon density”.
## [1] 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0
The code needed to have the indications of “from”, “to” and “by”