x <- c(
1.2, 1.5, 2.1, 2.5, 2.7, 2.2, 3.1, 4.5, 5.6, 5.5,
5.3, 2.3, 7.1, 4.2, 6.9, 5.3, 8.5, 8.1, 7.9, 4.5,
9.7, 8.9, 1.1, 2.8, 5.4, 8.8, 5.6, 7.8, 3.5, 6.6
)
y <- c(
3.1, 2.6, 3.7, 3.1, 4.1, 5.1, 2.7, 8.1, 6.2, 6.8,
6.4, 6.4, 4.3, 4.5, 5.4, 4.6, 4.5, 6.6, 5.9, 3.1,
8.1, 5.6, 4.2, 3.8, 5.6, 9.4, 2.3, 5.5, 4.5, 7.6
df <- data.frame(x, y)
b <- coef(lm(y ~ x))[1]
k <- coef(lm(y ~ x))[2]
df$yEst <- k * df$x + b
p <- list(x = 5.6, y = 2.3)
pEst <- subset(df, df$x == p$x & df$y == p$y)$yEst
op <- par()
par(family = 'Times')
plot(
df$x, df$y, type = 'p', pch = 20, col = 'black', bty = 'n', xaxt = 'n', yaxt = 'n', ann = FALSE, xlim = c(0, 11), ylim = c(0, 11)
arrows(0, 0, 11, 0, length = 0.15, angle = 10)
axis(side = 1, at = seq(0, 10, 1), tick = -0.015, pos = 0)
mtext('x', side = 1, line = -0.5, at = 11, cex = 1.1, font = 4)
arrows(0, 0, 0, 11, length = 0.15, angle = 10)
axis(side = 2, at = seq(0, 10, 1), tick = -0.015, pos = 0, las = 2)
mtext('y', side = 2, line = -0.5, at = 11, cex = 1.1, font = 4, las = 2)