Q1 Plot the relationship between the following continuous independent variable and treasure. For each plot, add axis and plot labels and a regression line showing the relationship between the independent and dependent variables.
size
cannons
date
decorations
daysfromshore
speed
library(yarrr)
capture.lm <- lm(treasure ~ size,
data = capture)
summary(capture)
## size cannons style warnshot
## Min. :37.00 Min. : 0.00 classic: 93 Min. :0.000
## 1st Qu.:47.00 1st Qu.:18.00 modern :907 1st Qu.:0.000
## Median :50.00 Median :32.00 Median :0.000
## Mean :50.06 Mean :32.86 Mean :0.202
## 3rd Qu.:53.00 3rd Qu.:46.00 3rd Qu.:0.000
## Max. :63.00 Max. :96.00 Max. :1.000
## date heardof decorations daysfromshore
## Min. : 1.00 Min. :0.000 Min. : 1 Min. : 1.00
## 1st Qu.: 91.75 1st Qu.:0.000 1st Qu.: 2 1st Qu.: 8.00
## Median :185.00 Median :0.000 Median : 4 Median :15.00
## Mean :183.30 Mean :0.281 Mean : 4 Mean :15.43
## 3rd Qu.:275.00 3rd Qu.:1.000 3rd Qu.: 6 3rd Qu.:23.00
## Max. :365.00 Max. :1.000 Max. :10 Max. :30.00
## speed treasure
## Min. :10.00 Min. : 835
## 1st Qu.:18.00 1st Qu.:1595
## Median :20.00 Median :1900
## Mean :20.12 Mean :2104
## 3rd Qu.:22.00 3rd Qu.:2251
## Max. :29.00 Max. :5615
plot(x = capture$size,
y = capture$treasure,
xlab = "Size of the ship",
ylab = "Ammount of treasure",
main = "Relation between ship size and treasure", pch = 16, col = gray(.05, .15)
)
abline(capture.lm)

capture.lm.2 <- lm(treasure ~ cannons,
data = capture)
plot(x = capture$cannons,
y = capture$treasure,
xlab = "Canons on ship",
ylab = "Ammount of treasure",
main = "Relation between ship cannons and treasure", pch = 16, col = gray(.05, .15)
)
abline(capture.lm.2,
col="hotpink")

capture.lm.3 <- lm(treasure ~ date,
data = capture)
plot(x = capture$date,
y = capture$treasure,
xlab = "Date",
ylab = "Ammount of treasure",
main = "Relation between date and treasure", pch = 16, col = gray(.05, .15)
)
abline(capture.lm.3,
col="green")

capture.lm.4 <- lm(treasure ~ decorations,
data = capture)
plot(x = capture$decorations,
y = capture$treasure,
xlab = "Decorations of a ship",
ylab = "Ammount of treasure",
main = "Relation between ship-decorations and treasure", pch = 16, col = gray(.05, .15)
)
abline(capture.lm.4,
col="blue")

capture.lm.5 <- lm(treasure ~ daysfromshore,
data = capture)
plot(x = capture$daysfromshore,
y = capture$treasure,
xlab = "Days from shore",
ylab = "Ammount of treasure",
main = "Relation between days off shore and treasure", pch = 16, col = gray(.05, .15)
)
abline(capture.lm.5,
col="red")

capture.lm.6 <- lm(treasure ~ speed,
data = capture)
plot(x = capture$speed,
y = capture$treasure,
xlab = "Speed of a ship",
ylab = "Ammount of treasure",
main = "Relation between ship-speed and treasure", pch = 16, col = gray(.05, .15)
)
abline(capture.lm.6,
lwd = 3,
col="yellow")

Q2 style
warnshot
heardof as IV to D treasure, add regression and pirateplot
pirateplot(dv.name = "treasure",
iv.name = "style",
data = capture,
my.palette = "espresso",
add.hdi = F
)

pirateplot(dv.name = "treasure",
iv.name = "warnshot",
data = capture,
my.palette = "drugs",
add.hdi = F
)

pirateplot(dv.name = "treasure",
iv.name = "heardof",
data = capture,
my.palette = "monalisa",
add.hdi = F
)

Q4
corr.capture<-cor.test(~ cannons + size,
data = capture)
names(corr.capture)
## [1] "statistic" "parameter" "p.value" "estimate" "null.value"
## [6] "alternative" "method" "data.name" "conf.int"
corr.capture$p.value
## [1] 0.3656786
capture.lm.new<-lm(size ~ cannons,
data = capture)
summary(capture.lm.new)
##
## Call:
## lm(formula = size ~ cannons, data = capture)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12.9844 -2.8873 -0.0596 2.9028 13.1409
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 49.859132 0.262458 189.970 <2e-16 ***
## cannons 0.006266 0.006923 0.905 0.366
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.14 on 998 degrees of freedom
## Multiple R-squared: 0.00082, Adjusted R-squared: -0.0001812
## F-statistic: 0.819 on 1 and 998 DF, p-value: 0.3657