-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestimate_warming_idealised.R
66 lines (52 loc) · 1.98 KB
/
estimate_warming_idealised.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Linear fit to polynomial function
# This code makes the plots for a blog post to illustrate that linear regression is
# not a good way to estimate total warming.
expo = seq(from=0.2, to=4, by=0.05)
noExpo = length(expo)
tempDiffs = vector(mode="numeric", length=noExpo)
for(iExp in 1:noExpo) {
fileName = paste0("fig3_fit_exp", expo[[iExp]] ,".png")
png(file=fileName, 700, 600, type="cairo")
noVal = 100 # Number of values (minus one)
t = (0:noVal)/noVal
y = t^expo[[iExp]]
yearBegin = 0
yearEnd = 1
fitLin = lm(y ~ t)
sumfit_high=summary(fitLin)
beginTempLin = predict(fitLin, data.frame(t=0))
endTempLin = predict(fitLin, data.frame(t=1))
tempDiffLin = endTempLin - beginTempLin
print(tempDiffLin)
tempDiffs[iExp] = tempDiffLin
yMin = min(c(beginTempLin, min(y)))
yMax = max(c(endTempLin, max(y)))
yMin = 0.1*floor(yMin*10)
yMax = 0.1*ceiling(yMax*10)
plot(t, y, type="l", col="gray", lwd=4, cex=1.5, cex.lab=1.5, cex.axis=1.5,
cex.main=1.5, xlab="Time", ylab="Value", ylim=c(yMin, yMax))
abline(0,0)
grid()
abline(fitLin, col="darkgreen", lwd=4)
lines(c(yearBegin, yearEnd), c(beginTempLin, beginTempLin), col="darkgreen", lwd=4, lty=5)
lines(c(yearEnd*0.6, yearEnd), c(endTempLin, endTempLin), col="darkgreen", lwd=4, lty=5)
arrows(yearEnd, beginTempLin, yearEnd, endTempLin, col="darkgreen", length=0.15, angle=30, code=3, lwd=3)
x = 0.95
y = mean(c(beginTempLin, endTempLin))
textStr = sprintf("Linear\n%.2f", tempDiffLin)
text(x, y, textStr, adj=c(1,NA), col="darkgreen", cex=2)
x = 0
y = 1
textStr = bquote("f(t)=t"^{.(expo[[iExp]])})
text(x, y, textStr, adj=c(0,NA), col="darkgreen", cex=2)
dev.off()
a=0
}
fileName = paste0("fig4_warming_estimates.png")
png(file=fileName, 700, 600, type="cairo")
plot(expo, tempDiffs, type="l", col="darkred", lwd=2, cex=1.5, cex.lab=1.5, cex.axis=1.5,
cex.main=1.5, xlab="Exponent", ylab="Linear warming estimate")
abline(0,0)
grid()
dev.off()
a=0