########################################################################### ### Quadratic Polynomial fit to selected harvested Right Whale oil ### Produced by Thomas J. Pfaff for sustainabilitymath.org ### March 2023 ########################################################################### ## URL for the data from sustainabilitymath.org dataURL<-"https://sustainabilitymath.org/excel/Whale-R.csv" ## Read data from online csv file Whale <-read.csv(url(dataURL),header=TRUE) names(Whale) ## Define x and y, mostly to save typing x<-Whale$years.since.1800 y<-Whale$whale.thousand.gallons #define variables with selected time frame x1<-x[c(14:42)] y1<-y[c(14:42)] ## Define some graphing parameters d<-2.25 #dot size 2.25 for webgraph, 1.25 for document l<-5 #line width 5 for webgraph, 2 for document ## Create Plot par(bg = "#b3c0d7") #Blue background for webgraph, comment out with # for white background. plot(x1, y1 ,type="p", cex=d, pch=10, xlim=c(17,50), ylim=c(0,12000), xlab="Years Since 1800", ylab="Thousands of Gallons") title(main="Right Whale Oil Harvested") grid (NULL,NULL, lty = 6, col = "gray") mtext("Thomas J. Pfaff || sustainabilitymath.org",1,4,adj=1) ## Quadratic fit to whale oild data model1<-lm(y1~x1+I(x1^2)) summary(model1) options(digits=10) options(scipen=999) Whale.coef=coef(model1) p1<-function(x){Whale.coef[[1]] + Whale.coef[[2]]*x +Whale.coef[[3]]*x^2 } plot(p1, xlim=c(17,47), type="l", lty=1, col="black", lwd=l, add=TRUE) Whale.coef ## Add question mark to graph text(49,11200, labels="?", cex=4)