Closed szcf-weiya closed 3 years ago
Figure 6.9 has been reproduced in https://esl.hohoweiya.xyz/rmds/lattice.html. It shows that
wind
and temp
, ozone
tends to increase along radiation
, which can be observed from almost every panels, except that the ozone can decrease a little when radiation is highest, such as panel (4, 3).wind
, i.e., for each row, the increasing magnitude and baseline of ozone
along radiation
would be increasing for the increasing temp
. Or in other words, further given radiation
, say the two extreme points, ozone
tends to increase along temp
.temp
, i.e., for each column, the baseline (or say the minimum and maximum) of ozone
along radiation
decreases along wind
# GAM
library(gam)
fit = gam(I(ozone^(1/3))~s(temperature) + s(wind) + s(radiation), data = data)
par(mfrow=c(1, 3))
plot(fit, se = T)
It is clear that the contribution of each feature captures the same pattern as concluded for Fig. 6.9.
temp
increases along temp
wind
decreases along wind
radiation
increases along radiation
library(rpart)
library(rpart.plot)
fit.tree = rpart(I(ozone^(1/3))~ temperature + wind + radiation, data = data)
rpart.plot(fit.tree)
Note that the response value in the leaf node increases from left to right, then we can observe that
radiation
goes to the left, i.e., ozone
tends to increase along radiation
.temp
goes to the left, i.e., ozone
tends to increase along temp
.wind
goes to the right, i.e. ozone
tends to decrease along wind
.> # MARS
> library(earth)
> fit.mars = earth(I(ozone^(1/3))~ temperature + wind + radiation, data = data)
> summary(fit.mars)
Call: earth(formula=I(ozone^(1/3))~temperature+wind+radiation, data=data)
coefficients
(Intercept) 2.72035983
h(temperature-73) 0.07721326
h(temperature-90) -0.11780995
h(9.7-wind) 0.17106469
h(225-radiation) -0.00317888
Selected 5 of 14 terms, and 3 of 3 predictors
Termination condition: Reached nk 21
Importance: temperature, wind, radiation
Number of terms at each degree of interaction: 1 4 (additive model)
GCV 0.2185924 RSS 20.48861 GRSq 0.7267643 RSq 0.7650625
Note the basis function and the sign of coefficients,
temp
, positive coef in [73, 90], and then negative coef in [90, ~], which indicates that ozone
tends to increase along temp
, but a little decrease for higher temp
. The tail decreasing pattern has also been shown in the lower confidence curve in GAMwind
, positive coef in [9.7, ~], which indicates that ozone
tends to decrease along wind
radition
, negative coef in [225, ~], which indicates that ozone
tends to increase along radiation
Interestingly, the reflection pairs do not return as in https://github.com/szcf-weiya/ESL-CN/blob/3aefb0bc171e272ca87af159e1d665d1d56b4c9f/code/MARS/simulation.R
library(prim)
fit.prim = prim.box(as.matrix(data[,-1]), as.numeric(data[, 1]))
summary(fit.prim, print.box = T)
plotprim = function(x, y, box = box, ...) {
plot(x, y, ...)
rect(box[1, 1], box[1, 2], box[2, 1], box[2, 2], border = "red")
}
colname = colnames(data)
par(mfrow = c(1, 3))
for (i in 2:3)
for (j in (i+1):4)
plotprim(data[,i], data[, j], fit.prim$box[[1]][,c(i-1, j-1)],
xlab = colname[i], ylab = colname[j])
It seems that plot.prim
does not plot the box, and also cannot superimpose on the original observation points, so I wrote the plot function by myself.
Note that the box indicates large ozone
, so it reveals that
radiation
tends to have large ozone
, i.e., increasewind
tends to have large ozone
, i.e., decreasetemp
tends to have large ozone
, i.e., increaseConclusion: all these methods obtain similar results in terms of the trend of every single variable.