Memuat
Memuat
Quantile Regression for Education and Learning
0 views
Comparing the effect of books at home and weekly reading hours on reading literacy score across quantiles with quantile regression (the analysis is illustrated with synthetic data). Quantile regression estimates predictor effects at several quantiles (for example 0.1, the median and 0.9) of the outcome distribution rather than only at its mean. It suits theses with skewed or heteroscedastic data such as wages, spending or waiting times.

Comparing the effect of books at home and weekly reading hours on reading literacy score across quantiles with quantile regression (the analysis is illustrated with synthetic data).
| Role | Variable | Unit |
|---|---|---|
| Main | Reading literacy score | score |
| Supporting 1 | Books at home | count |
| Supporting 2 | Weekly reading hours | hours |
The effect of Books at home on Reading literacy score moves from 0.407 at the 0.1 quantile to 0.657 at the median and 1.226 at the 0.9 quantile, whereas OLS gives 0.781. The equal-slopes test across quantiles (p < 0.001) shows the effect differs between the lower and upper tails, so quantile regression adds insight.
Computed from illustrative synthetic data, not from a real study.
Quantile regression estimates predictor effects at several quantiles (for example 0.1, the median and 0.9) of the outcome distribution rather than only at its mean. It suits theses with skewed or heteroscedastic data such as wages, spending or waiting times.
The coefficient at a given tau is the change in that quantile per one-unit increase in the predictor; compare it across quantiles and with OLS. Report the coefficient table by quantile, the equal-slopes test and the coefficient process plot.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
# Contoh kode R: Quantile Regression
suppressPackageStartupMessages({
library(ggplot2)
library(patchwork)
library(quantreg)
})
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: Y menceng ke kanan dan sebarannya melebar seiring X1 ----
n <- 200
d <- data.frame(books_at_home = rnorm(n, 50, 10),
weekly_reading_hours = rnorm(n, 30, 6))
z1 <- as.numeric(scale(d$books_at_home))
z2 <- as.numeric(scale(d$weekly_reading_hours))
b1 <- runif(1, 0.3, 0.55)
b2 <- runif(1, 0.12, 0.3) * sample(c(-1, 1), 1)
skala_galat <- exp(runif(1, 0.3, 0.5) * z1) # heteroskedastis: galat membesar saat X1 naik
galat <- (rgamma(n, shape = 2, rate = 2) - 1) * runif(1, 0.6, 0.8) # galat menceng ke kanan, rata-rata 0
y <- 100 + 15 * (b1 * z1 + b2 * z2 + skala_galat * galat)
d$reading_literacy_score <- round(pmax(y, 100 - 2.5 * 15, 0.02 * abs(100)), 3)
write.csv(d, "data_contoh.csv", row.names = FALSE)
# ---- Analisis: regresi kuantil (quantreg::rq) dan OLS sebagai pembanding ----
taus <- c(0.1, 0.25, 0.5, 0.75, 0.9)
fit <- rq(reading_literacy_score ~ books_at_home + weekly_reading_hours, tau = taus, data = d)
sq <- summary(fit, se = "nid") # SE metode Hendricks-Koenker (sandwich)
print(sq)
ols <- lm(reading_literacy_score ~ books_at_home + weekly_reading_hours, data = d)
print(summary(ols))
koef_q <- sapply(sq, function(s) s$coefficients[2, 1]) # koefisien X1 tiap kuantil
p_q <- sapply(sq, function(s) s$coefficients[2, 4])
# Uji kesamaan slope antarkuantil (Wald, Koenker-Bassett) untuk X1
fq <- lapply(c(0.1, 0.5, 0.9), function(t) rq(reading_literacy_score ~ books_at_home + weekly_reading_hours, tau = t, data = d))
uj <- anova(fq[[1]], fq[[2]], fq[[3]], joint = FALSE)
print(uj)
p_sama <- as.numeric(uj$table[1, "pvalue"])
# Pseudo R1 Koenker-Machado pada median
f50 <- fq[[2]]
f50_0 <- rq(reading_literacy_score ~ 1, tau = 0.5, data = d)
r1 <- 1 - sum(abs(residuals(f50))) / sum(abs(residuals(f50_0)))
# ---- Grafik ----
# Garis kuantil terhadap X1 (X2 ditahan pada rata-ratanya)
cf <- coef(fit)
gl <- data.frame(tau = factor(taus), a = cf[1, ] + cf[3, ] * mean(d$weekly_reading_hours), b = cf[2, ])
ab_ols <- c(coef(ols)[1] + coef(ols)[3] * mean(d$weekly_reading_hours), coef(ols)[2])
warna_tau <- setNames(c(pal[1], pal[3], pal[2], pal[3], pal[1]), levels(gl$tau))
p1 <- ggplot(d, aes(books_at_home, reading_literacy_score)) +
geom_point(colour = warna$redup, alpha = 0.35, size = 1.4) +
geom_abline(data = gl, aes(intercept = a, slope = b, colour = tau, linetype = tau), linewidth = 1) +
geom_abline(intercept = ab_ols[1], slope = ab_ols[2], colour = pal[4], linewidth = 0.9, linetype = "dotted") +
scale_colour_manual(values = warna_tau, name = "Quantile") +
scale_linetype_manual(values = c("dashed", "longdash", "solid", "longdash", "dashed"), name = "Quantile") +
labs(title = "Quantile lines 0.1 to 0.9 (dotted = OLS)", x = "books_at_home", y = "reading_literacy_score")
# Proses koefisien lintas tau dengan pita CI 95% dan garis OLS
tg <- seq(0.05, 0.95, by = 0.05)
proses <- do.call(rbind, lapply(tg, function(t) {
s <- tryCatch(summary(rq(reading_literacy_score ~ books_at_home + weekly_reading_hours, tau = t, data = d), se = "nid")$coefficients,
error = function(e) summary(rq(reading_literacy_score ~ books_at_home + weekly_reading_hours, tau = t, data = d), se = "iid")$coefficients)
data.frame(tau = t, var = c("x1", "x2"), b = s[2:3, 1], lo = s[2:3, 1] - 1.96 * s[2:3, 2],
hi = s[2:3, 1] + 1.96 * s[2:3, 2])
}))
ci_ols <- confint(ols)
garis_ols <- data.frame(var = c("x1", "x2"), b = coef(ols)[2:3], lo = ci_ols[2:3, 1], hi = ci_ols[2:3, 2])
plot_proses <- function(v, w, judul) {
ggplot(proses[proses$var == v, ], aes(tau, b)) +
geom_rect(data = garis_ols[garis_ols$var == v, ], aes(xmin = -Inf, xmax = Inf, ymin = lo, ymax = hi),
inherit.aes = FALSE, fill = pal[4], alpha = 0.12) +
geom_hline(data = garis_ols[garis_ols$var == v, ], aes(yintercept = b), colour = pal[4], linetype = "dotted", linewidth = 0.9) +
geom_hline(yintercept = 0, colour = warna$redup, linewidth = 0.4) +
geom_ribbon(aes(ymin = lo, ymax = hi), fill = w, alpha = 0.22) +
geom_line(colour = w, linewidth = 1.1) + geom_point(colour = w, size = 1.6) +
labs(title = judul, x = "Quantile (tau)", y = "Coefficient")
}
p2 <- plot_proses("x1", pal[2], paste("Effect of", substr("books_at_home", 1, 30)))
p3 <- plot_proses("x2", pal[5], paste("Effect of", substr("weekly_reading_hours", 1, 30)))
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$25
excl. 11% VAT
Duration: 5 working days
Output: R files + result figures
Deliverables
Package 2 · most chosen
US$69
excl. 11% VAT
Duration: 9 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$150
excl. 11% VAT
Duration: 14-17 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. Quantile Regression is commonly used at this level in Education and Learning. 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$25, Package 2 (your data analysis and interpretation) US$69 and Package 3 (full guidance) US$150, 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