This example is using material from Noam Ross available at the following url: https://noamross.github.io/gams-in-r-course/chapter1.
source("mpg.R")
head(mpg)
## symbol loss make fuel aspir doors style drive eng.loc wb
## 1 3 NA alfa-romero gas std two convertible rwd front 88.6
## 2 3 NA alfa-romero gas std two convertible rwd front 88.6
## 3 1 NA alfa-romero gas std two hatchback rwd front 94.5
## 4 2 164 audi gas std four sedan fwd front 99.8
## 5 2 164 audi gas std four sedan 4wd front 99.4
## 6 2 NA audi gas std two sedan fwd front 99.8
## length width height weight eng.type cylinders eng.cc fuel.sys bore stroke
## 1 168.8 64.1 48.8 2548 dohc four 130 mpfi 3.47 2.68
## 2 168.8 64.1 48.8 2548 dohc four 130 mpfi 3.47 2.68
## 3 171.2 65.5 52.4 2823 ohcv six 152 mpfi 2.68 3.47
## 4 176.6 66.2 54.3 2337 ohc four 109 mpfi 3.19 3.40
## 5 176.6 66.4 54.3 2824 ohc five 136 mpfi 3.19 3.40
## 6 177.3 66.3 53.1 2507 ohc five 136 mpfi 3.19 3.40
## comp.ratio hp rpm city.mpg hw.mpg price
## 1 9.0 111 5000 21 27 13495
## 2 9.0 111 5000 21 27 16500
## 3 9.0 154 5000 19 26 16500
## 4 10.0 102 5500 24 30 13950
## 5 8.0 115 5500 18 22 17450
## 6 8.5 110 5500 19 25 15250
mod_city3 <- gam(
city.mpg ~ s(weight, by = drive) + s(length, by = drive) + s(price, by = drive) + drive,
data = mpg, method = "REML")
ft <- as_flextable(mod_city3)
ft
Component | Term | Estimate | Std Error | t-value | p-value | |
A. parametric coefficients | (Intercept) | 21.286 | 1.751 | 12.158 | 0.0000 | *** |
drivefwd | 2.573 | 1.933 | 1.331 | 0.1848 |
| |
driverwd | 3.060 | 2.277 | 1.344 | 0.1807 |
| |
Component | Term | edf | Ref. df | F-value | p-value | |
B. smooth terms | s(weight):drive4wd | 1.000 | 1.000 | 0.320 | 0.5726 |
|
s(weight):drivefwd | 4.076 | 5.005 | 10.469 | 0.0000 | *** | |
s(weight):driverwd | 5.056 | 5.915 | 1.876 | 0.1013 |
| |
s(length):drive4wd | 1.000 | 1.000 | 0.163 | 0.6870 |
| |
s(length):drivefwd | 1.001 | 1.001 | 3.588 | 0.0597 | . | |
s(length):driverwd | 1.910 | 2.387 | 1.041 | 0.4156 |
| |
s(price):drive4wd | 1.000 | 1.000 | 2.492 | 0.1161 |
| |
s(price):drivefwd | 1.000 | 1.000 | 4.019 | 0.0465 | * | |
s(price):driverwd | 1.000 | 1.000 | 17.010 | 0.0001 | *** | |
Signif. codes: 0 <= '***' < 0.001 < '**' < 0.01 < '*' < 0.05 | ||||||
Adjusted R-squared: 0.734, Deviance explained 0.759 | ||||||
-REML : 519.798, Scale est: 10.985, N: 201 |