Memuat
Memuat
Generalized Additive Model (GAM) for Informatics and Information Systems
0 views
The analysis is meant to trace the nonlinear relationships of CPU temperature and CPU load with server power use, demonstrated on synthetic data. A Generalized Additive Model (GAM) captures nonlinear relationships between predictors and the outcome with smooth (spline) functions whose flexibility is estimated from the data. It suits theses that expect curved relationships, such as the effect of temperature, age or dose.

The analysis is meant to trace the nonlinear relationships of CPU temperature and CPU load with server power use, demonstrated on synthetic data.
| Role | Variable | Unit |
|---|---|---|
| Main | Server power use | W |
| Supporting 1 | CPU temperature | °C |
| Supporting 2 | CPU load | % |
The smooth of CPU temperature has 2.89 edf (p < 0.001), indicating a clearly nonlinear relationship, and the smooth of CPU load has 4.71 edf (p < 0.001). The GAM explains 76.9% of the deviance in Server power use, with an AIC 49.3 points lower than the linear model.
Computed from illustrative synthetic data, not from a real study.
A Generalized Additive Model (GAM) captures nonlinear relationships between predictors and the outcome with smooth (spline) functions whose flexibility is estimated from the data. It suits theses that expect curved relationships, such as the effect of temperature, age or dose.
An edf close to 1 means a nearly linear relationship, while larger edf values indicate a more flexible curve; the p-value tests whether the smooth differs from zero. Report the edf, p-values, deviance explained, the AIC comparison with the linear model and the partial effect plots.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
# Contoh kode R: Generalized Additive Model (GAM)
suppressPackageStartupMessages({
library(ggplot2)
library(patchwork)
library(mgcv)
})
set.seed(42)
# ---- Gaya grafik ----
pal <- c("#1f6feb", "#e8590c", "#2f9e44", "#ae3ec9", "#f59f00")
warna <- list(bg = "#f4f6fa", panel = "#ffffff", teks = "#1f2933", redup = "#5f6b78", grid = "#e3e8ee", bar = "#1d3557")
tata <- 1
theme_set(theme_minimal(base_size = 11) + theme(legend.position = "bottom"))
# ---- Data sintetis: hubungan nonlinear ----
n <- 200
d <- data.frame(cpu_temperature = runif(n, 50 - 1.9 * 10, 50 + 1.9 * 10),
cpu_load = rnorm(n, 30, 6))
z1 <- as.numeric(scale(d$cpu_temperature))
z2 <- as.numeric(scale(d$cpu_load))
# Bentuk kurva dipilih acak: U terbalik, gelombang, atau jenuh (saturasi)
bentuk1 <- sample(1:3, 1)
f1 <- switch(bentuk1, -(z1 - runif(1, -0.4, 0.4))^2, sin(runif(1, 1.2, 1.7) * z1), log1p(exp(2.2 * z1)) - 0.25 * z1^2)
f2 <- if (runif(1) < 0.5) tanh(runif(1, 1, 1.8) * z2) else exp(0.6 * z2)
f1 <- as.numeric(scale(f1)); f2 <- as.numeric(scale(f2))
y <- runif(1, 0.6, 0.85) * f1 + runif(1, 0.3, 0.5) * sample(c(-1, 1), 1) * f2 + rnorm(n, 0, runif(1, 0.45, 0.65))
d$server_power_use <- round(100 + 15 * y, 3)
write.csv(d, "data_contoh.csv", row.names = FALSE)
# ---- Analisis: Generalized Additive Model (mgcv::gam, REML) ----
fit <- gam(server_power_use ~ s(cpu_temperature) + s(cpu_load), data = d, method = "REML")
s <- summary(fit)
print(s)
print(k.check(fit)) # cek kecukupan dimensi basis k (k-index)
lin <- gam(server_power_use ~ cpu_temperature + cpu_load, data = d, method = "REML") # pembanding: model linear
aic <- c(Linear = AIC(lin), GAM = AIC(fit))
print(aic)
uji <- anova(lin, fit, test = "F") # uji F aproksimasi: linear vs GAM
print(uji)
edf <- unname(s$s.table[, "edf"])
p_s <- unname(s$s.table[, "p-value"])
# ---- Grafik ----
# Efek parsial tiap smooth (skala Y, variabel lain pada rata-rata) dengan pita 95% dan residual parsial
efek <- function(v, w, lab) {
g <- data.frame(cpu_temperature = rep(mean(d$cpu_temperature), 150), cpu_load = rep(mean(d$cpu_load), 150))
g[[v]] <- seq(min(d[[v]]), max(d[[v]]), length.out = 150)
pr <- predict(fit, newdata = g, type = "terms", se.fit = TRUE)
j <- match(paste0("s(", v, ")"), colnames(pr$fit))
gg <- data.frame(x = g[[v]], m = pr$fit[, j], lo = pr$fit[, j] - 1.96 * pr$se.fit[, j], hi = pr$fit[, j] + 1.96 * pr$se.fit[, j])
tr <- predict(fit, type = "terms")
dp <- data.frame(x = d[[v]], r = tr[, j] + residuals(fit)) # residual parsial
ggplot() +
geom_hline(yintercept = 0, colour = warna$redup, linewidth = 0.4) +
geom_point(data = dp, aes(x, r), colour = warna$redup, alpha = 0.3, size = 1.1) +
geom_ribbon(data = gg, aes(x, ymin = lo, ymax = hi), fill = w, alpha = 0.25) +
geom_line(data = gg, aes(x, m), colour = w, linewidth = 1.3) +
geom_rug(data = dp, aes(x), sides = "b", colour = w, alpha = 0.3, length = unit(0.02, "npc")) +
labs(title = sprintf("Partial effect s(%s), edf = %.2f", substr(lab, 1, 14), s$s.table[j, "edf"]),
x = if (v == "cpu_temperature") "cpu_temperature" else "cpu_load", y = "Partial effect")
}
p1 <- efek("cpu_temperature", pal[1], "cpu_temperature")
p2 <- efek("cpu_load", pal[2], "cpu_load")
d$prediksi <- fitted(fit)
p3 <- ggplot(d, aes(prediksi, server_power_use)) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed", colour = warna$redup) +
geom_point(colour = pal[3], alpha = 0.55, size = 1.5) +
annotate("text", x = min(d$prediksi), y = max(d$server_power_use), hjust = 0, vjust = 1, colour = warna$teks, size = 3.3,
label = sprintf("Deviance explained = %.1f%%", 100 * summary(fit)$dev.expl)) +
labs(title = "Predicted vs actual", x = "Predicted server_power_use", y = "server_power_use")
p_hasil <- if (tata == 1) (p1 | p2) / p3 else p1 | (p2 / p3)
print(p_hasil)
The original project file is available. It is not just the picture above: you get the working R project. It can be downloaded after payment, and we send it by WhatsApp or email.
ZIP: analisis.R + data_contoh.csv + BACA-DULU.txt
Choose how much help you need. Each higher package includes everything in the lower ones. Prices exclude 11% VAT.
Package 1
US$34
excl. 11% VAT
Duration: 7 working days
Output: R files + result figures
Deliverables
Package 2 · most chosen
US$100
excl. 11% VAT
Duration: 13 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$219
excl. 11% VAT
Duration: 18-21 working days
Output: Code + analysis + guidance until ready to present
Includes all of Packages 1 & 2, plus
Yes. The original project file is a ZIP containing the complete analisis.R script, a data_contoh.csv sample dataset and a BACA-DULU.txt guide. It can be downloaded after payment, and we send it by WhatsApp or email. For your own data (Package 2 and 3) the script is adapted to your dataset.
Yes. Generalized Additive Model (GAM) is commonly used at this level in Informatics and Information Systems. We adapt the analysis to your research question, your own data and your supervisor's requirements.
No. The sheet is computed from illustrative synthetic data so you can see the kind of output R Studio gives. For your order we run the same method on your own data.
That is the point of the packages. Every script is commented, and Package 3 includes two coaching sessions plus practice questions so you can explain the method and the results at your seminar and defence.
Each project has three packages: Package 1 (code and explanation) US$34, Package 2 (your data analysis and interpretation) US$100 and Package 3 (full guidance) US$219, excluding 11% VAT. Larger datasets, extra methods or tight deadlines adjust the quote after a short consultation.
The result sheet uses illustrative synthetic data. R is a programming language of the R Foundation project; RStudio and Posit are trademarks of Posit PBC.
Back to R Studio portfolio