library(pixmap)
casablanca_pic <- read.pnm("casablanca.pgm")
casablanca_pic
plot(casablanca_pic)
dim(casablanca_pic@grey)
Set the working library
Code may like: setwd("~/Documents/CUdocs/2021Fall/STAT5206"
<aside>
š” locator()
Reads the position of the graphics cursor when the (first) mouse button is pressed
</aside>
<aside> š” Recycling: when a shorter vector is added to a longer one, the elements in the shorter vector are repeated
vāc(1,3,5)
v + c(1,3)
[1] 2 6 6
</aside>
# For thr line of best fit, y = a + bx (y, a, b are vectors)
dev_x <- x- mean(x)
dev_y <- y- mean(y)
Sxy <- sum(dev_x * dev_y)
Sxx <- sum(dev_x * dev_x)
# the estimated slope
slope <- Sxy/Sxx
# the estimated intercept
inter <- mean(y) - slope*mean(x)
abline(a = inter, b = slope)