Memuat
Memuat
Tobit and Heckman Selection Models for Tourism and Hospitality
0 views
Correct censoring or selection bias in souvenir spending using tourist income and visit duration using synthetic data for demonstration. The Tobit model handles a dependent variable censored at zero (many zero observations), while the Heckman selection model corrects the bias when the outcome is only observed for participants. It suits theses on spending, hours or wages that are often zero or unobserved.

Correct censoring or selection bias in souvenir spending using tourist income and visit duration using synthetic data for demonstration.
| Role | Variable | Unit |
|---|---|---|
| Main | Souvenir spending | IDR thousand |
| Supporting 1 | Tourist income | IDR million |
| Supporting 2 | Visit duration | days |
43.2% of Souvenir spending observations are zero, so OLS (Tourist income coefficient 8.423) is biased towards zero relative to the Tobit model (13.865; p < 0.001). The two-step Heckman model gives 8.876 for participants; the inverse Mills ratio (p = 0.080, rho = 0.34) shows no significant selection bias.
Computed from illustrative synthetic data, not from a real study.
The Tobit model handles a dependent variable censored at zero (many zero observations), while the Heckman selection model corrects the bias when the outcome is only observed for participants. It suits theses on spending, hours or wages that are often zero or unobserved.
Report the share of zeros, then compare the OLS, Tobit and Heckman coefficients to show the OLS bias. Tobit coefficients are effects on the latent variable, Heckman coefficients are effects for participants, and a significant inverse Mills ratio (non-zero rho) signals selection bias.
A short starting script with this project's variable names. The delivered version is adapted to your data and fully commented.
# Contoh kode R: Tobit and Heckman Selection Models
suppressPackageStartupMessages({
library(ggplot2)
library(patchwork)
library(AER)
library(sampleSelection)
})
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 bernilai nol untuk yang tidak berpartisipasi ----
n <- max(300, 200)
d <- data.frame(tourist_income = round(rnorm(n, 50, 10), 3),
visit_duration = round(rnorm(n, 30, 6), 3),
akses = round(rnorm(n, 50, 10), 1)) # variabel eksklusi: hanya memengaruhi partisipasi
z1 <- as.numeric(scale(d$tourist_income))
z2 <- as.numeric(scale(d$visit_duration))
za <- as.numeric(scale(d$akses))
rho <- runif(1, 0.3, 0.7) # korelasi galat seleksi dan galat outcome
u <- rnorm(n)
e <- rho * u + sqrt(1 - rho^2) * rnorm(n)
# persamaan seleksi (partisipasi)
g0 <- qnorm(runif(1, 0.55, 0.72))
d$partisipasi <- as.integer(g0 + runif(1, 0.4, 0.8) * z1 + runif(1, 0.1, 0.3) * z2 + runif(1, 0.6, 1) * za + u > 0)
# persamaan outcome (hanya teramati bila partisipasi = 1)
b1 <- runif(1, 0.25, 0.45); b2 <- runif(1, 0.08, 0.25) * sample(c(-1, 1), 1)
y_star <- 100 * (1 + b1 * z1 + b2 * z2 + 0.3 * e)
d$souvenir_spending <- round(ifelse(d$partisipasi == 1, pmax(y_star, 0), 0), 3)
write.csv(d, "data_contoh.csv", row.names = FALSE)
# ---- Analisis 1: OLS naif dan Tobit (tersensor kiri di 0) ----
ols <- lm(souvenir_spending ~ tourist_income + visit_duration, data = d)
tob <- tobit(souvenir_spending ~ tourist_income + visit_duration, left = 0, data = d)
print(summary(ols)); print(summary(tob))
st <- coef(summary(tob))
sig_tob <- tob$scale
# ---- Analisis 2: Heckman dua tahap (heckit) dengan variabel eksklusi akses ----
hk <- selection(selection = partisipasi ~ tourist_income + visit_duration + akses,
outcome = souvenir_spending ~ tourist_income + visit_duration, data = d, method = "2step")
print(summary(hk))
sh <- coef(summary(hk))
io <- hk$param$index$betaO # baris persamaan outcome
b_hk <- sh[io, ]; rownames(b_hk) <- c("(Intercept)", "tourist_income", "visit_duration")
imr <- sh[hk$param$index$Mills, ] # koefisien inverse Mills ratio (lambda)
rho_hat <- unname(coef(hk)["rho"])
p_imr <- unname(imr[4])
nol <- 100 * mean(d$souvenir_spending == 0)
cat(sprintf("Proporsi nol: %.1f%%, rho = %.3f, p IMR = %.4f\n", nol, rho_hat, p_imr))
# ---- Grafik ----
# 1) histogram Y dengan massa di nol
d$jenis <- factor(ifelse(d$souvenir_spending == 0, "Zero (censored / not observed)", "Positive"),
levels = c("Zero (censored / not observed)", "Positive"))
p1 <- ggplot(d, aes(souvenir_spending, fill = jenis)) +
geom_histogram(bins = 30, colour = warna$panel, alpha = 0.9) +
scale_fill_manual(values = c(pal[2], pal[1]), name = NULL) +
labs(title = sprintf("Distribution of souvenir_spending (%.0f%% zeros)", 100 * mean(d$souvenir_spending == 0)), x = "souvenir_spending", y = "Count")
# 2) koefisien tourist_income: OLS vs Tobit vs Heckman (IK 95%)
dk <- data.frame(model = factor(c("OLS", "Tobit", "Heckman"), levels = c("Heckman", "Tobit", "OLS")),
b = c(coef(ols)["tourist_income"], st["tourist_income", 1], b_hk["tourist_income", 1]),
se = c(coef(summary(ols))["tourist_income", 2], st["tourist_income", 2], b_hk["tourist_income", 2]))
dk$teks <- sprintf("%.3f", dk$b)
p2 <- ggplot(dk, aes(b, model, colour = model)) +
geom_errorbarh(aes(xmin = b - 1.96 * se, xmax = b + 1.96 * se), height = 0.18, linewidth = 1) +
geom_point(size = 3.2) +
geom_text(aes(label = teks), vjust = -1.2, size = 3, colour = warna$teks) +
scale_colour_manual(values = c(OLS = pal[2], Tobit = pal[1], Heckman = pal[3]), guide = "none") +
scale_y_discrete(expand = expansion(add = 0.7)) +
labs(title = "Coefficient of tourist_income (95% CI)", x = "Estimate", y = NULL)
# 3) prediksi E[Y] menurut tourist_income (X2 di rata-rata)
xs <- seq(min(d$tourist_income), max(d$tourist_income), length.out = 100)
nd <- data.frame(tourist_income = xs, visit_duration = mean(d$visit_duration))
xb <- as.numeric(model.matrix(~ tourist_income + visit_duration, nd) %*% coef(tob))
dp <- rbind(data.frame(x = xs, y = predict(ols, nd), model = "OLS"),
data.frame(x = xs, y = pnorm(xb / sig_tob) * xb + sig_tob * dnorm(xb / sig_tob), model = "Tobit E[Y]"),
data.frame(x = xs, y = as.numeric(model.matrix(~ tourist_income + visit_duration, nd) %*% b_hk[, 1]), model = "Heckman E[Y*]"))
p3 <- ggplot() +
geom_point(data = d, aes(tourist_income, souvenir_spending), colour = warna$redup, alpha = 0.3, size = 1.1) +
geom_line(data = dp, aes(x, y, colour = model), linewidth = 1.1) +
scale_colour_manual(values = c("OLS" = pal[2], "Tobit E[Y]" = pal[1], "Heckman E[Y*]" = pal[3]), name = NULL) +
labs(title = "Predicted souvenir_spending by tourist_income", x = "tourist_income", y = "souvenir_spending")
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$31
excl. 11% VAT
Duration: 7 working days
Output: R files + result figures
Deliverables
Package 2 · most chosen
US$88
excl. 11% VAT
Duration: 13 working days
Output: Code + analysis + interpretation notes
Includes all of Package 1, plus
Package 3
US$191
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. Tobit and Heckman Selection Models is commonly used at this level in Tourism and Hospitality. 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$31, Package 2 (your data analysis and interpretation) US$88 and Package 3 (full guidance) US$191, 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