Estimate the probit model using data oscar.csv of the form
\[winner_{i}^{*} = \beta_{0} + \beta_{1}nominations_{i} + \beta_{2}gglobes_{i} + \varepsilon_{i} \quad (1)\]
The dependent variable \(winner\) is a dummy variable (\(= 1\) if the movie won the best picture Oscar, \(= 0\) otherwise). We are going to use the number of nominations and the number of Golden Globes won by the movie as explanatory variables.
Are \(\beta_{1}\) and \(\beta_{2}\) jointly significant?
Calculate marginal effects for the average observation and for your own defined observation.
Calculate \(R^{2}\) statistics and interpret them.
Perform the model specification test (linktest).
Perform the Hosmer-Lemeshow test.
Perform the Osius-Rojek test.
Verify a hypothesis that \(\beta_{2} = 0\) using likelihood ratio test.
使用 oscar.csv 数据估计如下形式的 Probit 模型:
\[winner_{i}^{*} = \beta_{0} + \beta_{1}nominations_{i} + \beta_{2}gglobes_{i} + \varepsilon_{i} \quad (1)\]
因变量 \(winner\) 是一个虚拟变量(如果电影获得奥斯卡最佳影片奖,则取值为 1,否则为 0)。我们将使用电影获得的提名数量和金球奖获奖数量作为解释变量。
\(\beta_{1}\) 和 \(\beta_{2}\) 是否联合显著?
计算平均观测值以及你自己定义的观测值的边际效应。
计算 \(R^{2}\) 统计量并进行解释。
进行模型设定检验 (linktest)。
进行 Hosmer-Lemeshow 检验。
进行 Osius-Rojek 检验。
使用似然比检验 (LR test) 验证假设 \(\beta_{2} = 0\)。
这道题目要求你利用一个关于奥斯卡奖的数据集,通过 Probit 回归模型来分析一部电影是否能拿奖。
模型背景:你想预测一部电影能不能拿“最佳影片”(这是因变量,1代表拿奖,0代表没拿)。预测的依据(自变量)有两个:一是这部电影拿到了多少项提名,二是它拿到了多少个金球奖。
核心任务:
Sys.setenv(LANG = "en")
options(scipen = 5)
library("devtools")
library(WNE)
library("sandwich")
library("lmtest")
library("MASS")
library("mfx")
library("BaylorEdPsych")
# library("htmltools")
library("LogisticDx")
library("aod")
library("logistf") #Firth's bias reduction methodoscar = read.csv2(file="Oscar.csv", header=TRUE, sep=";")
# 删除数据集中含有缺失值(NA)的所有行。这是建模前的常规清洗步骤,
# 因为 glm 函数默认无法处理含有缺失值的观测。
oscar <- na.omit(oscar) # removed 5 entries
# probit model estimation
# 调用 广义线性模型 (Generalized Linear Model) 函数来估计模型参数,
# 并将结果保存在变量 myprobit 中。
# 符号 ~ 读作 "is modeled by"(由...建模)
myprobit <- glm(winner~nominations+gglobes, data=oscar,
family=binomial(link="probit"))这段代码展示了在 R 语言中进行 Probit 回归模型建模的标准流程。Probit 模型通常用于处理二元分类问题(如“得奖”或“未得奖”),它假设隐含的随机误差项服从标准正态分布。
oscar = read.csv2(file="Oscar.csv", header=TRUE, sep=";")
Oscar.csv
的数据文件。read.csv2
默认识别以分号(;)作为分隔符、逗号作为小数点的文件格式(常用于欧洲格式的
CSV)。header=TRUE 表示第一行是变量名。View(oscar)
oscar = na.omit(oscar)
NA)的所有行。这是建模前的常规清洗步骤,因为
glm 函数默认无法处理含有缺失值的观测。myprobit <- glm(...)
myprobit 中。在 glm() 函数内部,参数的含义如下:
winner ~ nominations + gglobes
winner
是因变量(Y),即我们要预测的结果。nominations 和 gglobes
是自变量(X),即预测因子。~ 读作 “is modeled by”(由…建模)。data = oscar
family = binomial(link = "probit")
binomial:告诉 R
这是一个二项分布族模型。因为 winner 只有 0 或 1
两个取值。link = "probit":指定使用
Probit 连接函数。
link,默认通常是
logit(逻辑回归)。这段代码就像是在教计算机“看规律”:
winner)和‘提名数’(nominations)以及‘金球奖数’(gglobes)之间的关系。”probit
这种数学规则(基于正态分布),计算出这两个因素对获奖概率的影响程度。运行完这段代码后,你只需输入
summary(myprobit),就能看到每个因素的具体权重(系数)以及它们是否真的统计显著了。
# predicted probabilities
oscar$prob = predict(myprobit,type=c("response"))
library(pROC)
g <- roc(winner ~ prob, data = oscar)
plot(g)
这段代码的核心任务是评估模型的预测能力。它通过计算每部电影获奖的预测概率,并绘制
ROC
曲线(受试者工作特征曲线)来直观展示模型的分类效果。
以下是详细解释:
oscar$prob = predict(myprobit, type=c("response"))
predict(): 这是 R
中通用的预测函数。type = "response": 这是最关键的参数。
type = "response" 后,R 会将 \(Z\) 分数通过标准正态分布函数 \(\Phi(z)\) 转换,输出 0 到 1
之间的概率值。oscar
数据框中新增加了一列
prob,记录了模型预测的每部电影获得奥斯卡的概率。library(pROC)
install.packages("pROC") 进行安装。g <- roc(winner ~ prob, data = oscar)
winner ~ prob
表示对比真实的获奖结果(winner)和模型预测的概率(prob)。g
存储了曲线的所有坐标点数据,以及最重要的指标
AUC(曲线下面积)。plot(g)
这段代码好比是给你的模型做一次“模拟考”:
##
## Call:
## glm(formula = winner ~ nominations + gglobes, family = binomial(link = "probit"),
## data = oscar)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -5.2314 1.0203 -5.127 0.000000294 ***
## nominations 0.3804 0.1005 3.786 0.000153 ***
## gglobes 0.6241 0.1748 3.570 0.000357 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 100.080 on 99 degrees of freedom
## Residual deviance: 45.501 on 97 degrees of freedom
## AIC: 51.501
##
## Number of Fisher Scoring iterations: 7
## (Intercept) nominations gglobes
## -5.2314277 0.3803681 0.6240719
## [1] 3.785894
这段代码的目的是从已经估算好的 Probit 模型中提取关键统计信息。以下是针对代码操作和控制台输出结果的详细解析:
summary(myprobit): 这是 R
中最常用的函数,用于显示模型的全面汇总报告,包括系数、标准误、z 值、p
值以及模型拟合优度指标(如离差 Deviance)。myprobit$coefficients:
直接从模型对象中提取回归系数(\(\beta\) 值)。summary(myprobit)$coefficients[2,3]:
这是一个精确提取操作。它进入汇总表的矩阵中,提取第 2 行、第 3
列的数值。
nominations(提名数)。z value(z 统计量)。根据 summary
的输出,我们可以得出以下计量经济学结论:
Pr(>|z|))都远小于
0.001(对应三个星号 ***)。nominations 和 gglobes
在统计上都是极显著的,它们对预测是否获得奥斯卡奖非常有帮助。这份报告告诉我们:“提名越多、金球奖拿得越多,奥斯卡封神的几率就越大。”
具体来说: * 金球奖的影响力 (0.6241) 看起来比 提名数的影响力 (0.3804) 更大一些(但注意,这是在 Probit 空间下的系数,直接对比数值不代表实际概率的直接倍数,需要计算边际效应)。 * 两个因素都通过了“显著性检验”,说明这不是巧合,而是真实存在的统计关联。
# Joint insignificance of all variables test
null_probit = glm(winner~1, data=oscar, family=binomial(link="probit"))
lrtest(myprobit, null_probit)## Likelihood ratio test
##
## Model 1: winner ~ nominations + gglobes
## Model 2: winner ~ 1
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 3 -22.75
## 2 1 -50.04 -2 54.58 1.407e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
这段代码和输出回答了题目中的 a)
问:nominations 和 gglobes
是否联合显著?
简单来说,这个测试是在检查:“带上这两个预测变量的模型,是不是真的比一个‘只靠猜’的模型强得多?”
null_probit = glm(winner ~ 1, ...)
1
代表只包含截距项(Intercept),不包含任何预测变量。lrtest(myprobit, null_probit)
根据 lrtest 的表格,我们可以看到以下关键点:
***。nominations 和 gglobes
联合显著。这个测试好比是在问:“我们费劲去数电影拿了多少个提名和金球奖,对预测奥斯卡到底有没有意义?”
统计结论:我们可以非常有信心地说,提名数量和金球奖数量共同决定了(或强烈关联着)一部电影是否能拿奥斯卡,这绝对不是随机凑巧的结果。
下一步建议:
既然已经确定了模型整体有效,你想看看如何进行 g) 问
的似然比检验吗?(即:只针对 gglobes
这一个变量进行检验,看它在已有提名数的情况下是否依然多余)。
English Version
Based on the Likelihood Ratio (LR) test comparing the full model (\(winner \sim nominations + gglobes\)) against the null model (\(winner \sim 1\)), the results are as follows:
Conclusion: We reject the null hypothesis. The variables nominations and gglobes are jointly significant at the \(0.1\%\) level. This indicates that the inclusion of these two variables significantly improves the model’s fit compared to a model with only an intercept.
中文版
基于全模型(包含提名数和金球奖数)与空模型(仅包含截距项)的似然比检验 (LR test),结果如下:
结论: 我们拒绝原假设。变量 nominations(提名数)和 gglobes(金球奖数)在 \(0.1\%\) 的水平下是联合显著的。这表明,相比于只靠常数项“瞎猜”的模型,引入这两个变量显著提高了模型对奥斯卡获奖结果的预测能力。
通俗解释
简单来说,这个检验是在问:“我们费劲去统计提名数和金球奖数,对预测奥斯卡到底有没有用?”
答案是:非常有用。 统计结果显示,这两个因素加在一起绝对不是“摆设”,它们提供的预测信息非常强大,出错的概率(P值)微乎其微。
# marginal effects for the average observation
(meff = probitmfx(formula=winner~nominations+gglobes, data = oscar, atmean=TRUE))## Call:
## probitmfx(formula = winner ~ nominations + gglobes, data = oscar,
## atmean = TRUE)
##
## Marginal Effects:
## dF/dx Std. Err. z P>|z|
## nominations 0.043022 0.017707 2.4296 0.01511 *
## gglobes 0.070586 0.029389 2.4018 0.01632 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
这段代码计算的是 b) 问 中要求的“平均观测值的边际效应”(Marginal Effects at the Mean, MEM)。
与之前我们讨论的“系数”不同,这里的 dF/dx
列给出的就是直观的概率变动数值。
在 ==Probit== 模型中,==边际效应==表示:当某个自变量增加 1 个单位时,电影赢得奥斯卡的“概率”具体会改变多少(以==百分比==计算)。
| 变量 | dF/dx (边际效应) | P 值 | 解读 (在平均水平下) |
|---|---|---|---|
| nominations | 0.0430 | 0.01511 | 每增加 1 项提名,获奖概率平均增加约 4.3%。 |
| gglobes | 0.0706 | 0.01632 | 每增加 1 个金球奖,获奖概率平均增加约 7.1%。 |
atmean = TRUE:
dF/dx:
z 和 P>|z|:
*),说明在 5%
的显著性水平下,这些边际效应是统计显著的。For an “average” movie in the dataset, the marginal effects show that:
Both effects are statistically significant at the 5% level (\(p < 0.05\)).
对于数据集中的“平均水平”电影,边际效应结果显示:
这两个结果在 5% 的显著性水平下均具有统计学意义。
这回我们终于拿到“实锤”的数据了:
## Marginal effects at X=
## nominations 0.04302200 7.43
## gglobes 0.07058642 1.31
## Marginal effects at X=
## nominations 0.02847637 12
## gglobes 0.04672134 4
For an average observation (\(X=7.43, 1.31\)), the marginal effects are 4.30% for nominations and 7.06% for Golden Globes. However, for a high-performing movie with 12 nominations and 4 Golden Globes, the marginal effects decrease to 2.85% and 4.67% respectively. This illustrates the non-linear nature of the Probit model, where marginal impacts diminish as the predicted probability approaches certainty.
对于平均观测值(\(7.43\) 项提名,\(1.31\) 个金球奖),提名和金球奖的边际效应分别为 4.30% 和 7.06%。然而,对于一部拥有 12 项提名和 4 个金球奖 的热门电影,其边际效应分别降至 2.85% 和 4.67%。这说明了 Probit 模型的非线性特征:当预测概率接近 \(1\) 时,额外增加变量带来的概率提升会逐渐减小。
## McFadden Adj.McFadden Cox.Snell Nagelkerke
## 0.5453574 0.4654217 0.4206198 0.6650993
## McKelvey.Zavoina Effron Count Adj.Count
## 0.7066451 0.5543767 0.9000000 0.5000000
## AIC Corrected.AIC
## 51.5008529 51.7508529
在==普通==的回归分析中,\(R^2\) 告诉我们模型解释了多少波动的比例。但在 ==Probit== 这种“==是非题==”(0 或 1)模型中,情况复杂一些,所以 R 给出了好几个 Pseudo \(R^2\)(伪 \(R^2\))。
虽然它们算出来的数值各异,但它们共同传达了一个核心信息:你的模型表现非常出色。
通俗解释:它衡量了模型相比于“完全瞎猜”提升了多少。
判定标准:在 Probit/Logit 模型中,McFadden \(R^2\) 只要在 0.2 到 0.4 之间,就已经被认为模型拟合得相当完美了。
你的结果:你的值是 0.545。这说明提名数和金球奖数这两个变量对预测奥斯卡奖有着极强的解释力,模型非常扎实。
The McFadden \(R^2\) of 0.545 indicates an excellent model fit, as values between 0.2 and 0.4 are typically considered highly satisfactory for discrete choice models.
Furthermore, the Count \(R^2\) of 0.900 shows that the model correctly predicts the outcome for 90% of the observations.
Overall, the model has strong explanatory and predictive power.
McFadden \(R^2\) 为 0.545,这表明模型拟合度极高(通常在 Probit 模型中,该值超过 0.2 即可视为表现优异)。
同时,Count \(R^2\) 为 0.900,意味着模型对 90% 的样本做出了正确的分类预测。
综合来看,该模型具有很强的解释力和预测力。
## Linktest
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.06099 0.24205 -0.252 0.802
## _hat 0.62148 0.15331 4.054 0.000 ***
## _hatsq 0.03027 0.03331 0.909 0.366
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
这部分代码执行的是 d) 问 中的 Linktest(模型设定检验)。简单来说,这是在给你的模型做“逻辑体检”,看看你选择的 Probit 模型形式以及放进去的变量是否合适。
Linktest
的原理很有趣:它假设如果你原来的模型设定是正确的,那么预测出来的结果(_hat)应该足以解释因变量。如果你把预测结果的平方(_hatsq)也放进模型,这个平方项不应该具有显著的解释力。
在输出的表格中,我们重点看 _hat 和 _hatsq
这两行:
根据这个测试结果,你可以得出以下结论:
The linktest results show that the p-value for **_hatsq** is 0.366, which is much higher than the 0.05 significance level. This means we fail to reject the null hypothesis that the model is correctly specified. Therefore, the probit link function is appropriate, and there is no evidence of functional form misspecification (such as missing interaction terms or non-linearities).
Linktest 结果显示,**_hatsq** 的 P 值为 0.366,远大于 0.05 的显著性水平。这意味着我们无法拒绝“模型设定正确”的原假设。因此可以认为,当前使用的 Probit 模型形式是合适的,没有证据表明模型存在严重的设定偏误(例如漏掉变量的平方项或交互项)。
Linktest
就像是在问模型一个问题:“既然你已经算出了一套预测概率(_hat),那如果我再给你一个这些概率的平方项(_hatsq),你还能挖出更多没发现的秘密吗?”
你的结果是 0.366(不显著),说明你的模型很健康,设定得没毛病。
## test stat val df pVal
## <char> <char> <num> <num> <num>
## 1: HL chiSq 1.33728868 8 0.9950915
## 2: mHL F 0.09489453 9 0.9995517
## 3: OsRo Z -0.07493241 NA 0.9402685
## 4: SstPgeq0.5 Z 0.81554751 NA 0.4147590
## 5: SstPl0.5 Z 0.23693523 NA 0.8127070
## 6: SstBoth chiSq 0.72125604 2 0.6972383
## 7: SllPgeq0.5 chiSq 1.07826236 1 0.2990866
## 8: SllPl0.5 chiSq 0.05549122 1 0.8137697
## 9: SllBoth chiSq 1.63582136 2 0.4413528
The Hosmer-Lemeshow (HL) and Osius-Rojek (OsRo) tests evaluate how well the predicted probabilities match the actual outcomes.
Conclusion: Both tests indicate an excellent fit. The small \(chiSq\) and the \(Z\)-score near \(0\) represent minimal discrepancy between the model’s predictions and the observed data.
Hosmer-Lemeshow (HL) 检验和 Osius-Rojek (OsRo) 检验用于评估模型预测的概率与实际结果的吻合程度。
结论:这两项检验均表明模型表现优异。较小的卡方值和接近 \(0\) 的 \(Z\) 分数代表模型预测与实际数据之间的偏差极小,拟合度非常高。
这两项检验就像是在给模型做“精准度体检”:
简而言之,你的模型不仅能分清谁能拿奖,而且它给出的每一个概率百分比都经得起现实数据的推敲。
在二元选择模型(如 Probit)中,ROC 曲线是衡量模型分类能力(即区分“谁会赢”和“谁不赢”)最权威的图表。
1. 核心数值解读: * AUC (Area Under the Curve): 94.2% * 置信区间 (95% CI): 89.1% – 99.2%
2. 通俗解释: * 什么是 AUC?:AUC 是曲线下方的面积。如果 AUC 是 0.5(图中那条对角虚线),说明模型在瞎猜;如果 AUC 是 1.0,说明模型是百分之百准确的神算子。 * 你的结果 (94.2%):这代表如果你随机选出一组“获奖电影”和“未获奖电影”,你的模型有 94.2% 的概率能准确指出哪部才是真正的赢家。
English Version The ROC Curve and its AUC (Area Under the Curve) provide a comprehensive measure of the model’s predictive accuracy. * Result: The AUC is 94.2% (95% CI: 89.1%–99.2%). * Conclusion: An AUC above 0.90 is generally considered outstanding. This indicates that the Probit model has an excellent ability to discriminate between Oscar winners and non-winners based on the provided predictors (nominations and Golden Globes).
中文版 ROC 曲线及其曲线下面积 (AUC) 提供了对模型预测准确性的综合衡量。 * 结果:AUC 值为 94.2%(95% 置信区间为 89.1%–99.2%)。 * 结论:在统计学中,AUC 超过 0.90 通常被视为表现极佳(Outstanding)。这表明该 Probit 模型在区分奥斯卡“获奖者”与“非获奖者”方面具有卓越的能力,预测效果非常精准。
之前的 \(R^2\) 告诉我们模型解释了多少波动,而 ROC 曲线 则直接告诉我们模型在实战分类中的成功率。
94.2% 的 AUC 配合之前 0.995 的 HL 检验 P 值,共同构成了一个无懈可击的论据:你的模型不仅逻辑正确(设定稳健),而且实战精准(预测力强)。
myprobit <- glm(winner~nominations+gglobes, data=oscar,
family=binomial(link="probit"))
summary(myprobit)##
## Call:
## glm(formula = winner ~ nominations + gglobes, family = binomial(link = "probit"),
## data = oscar)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -5.2314 1.0203 -5.127 0.000000294 ***
## nominations 0.3804 0.1005 3.786 0.000153 ***
## gglobes 0.6241 0.1748 3.570 0.000357 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 100.080 on 99 degrees of freedom
## Residual deviance: 45.501 on 97 degrees of freedom
## AIC: 51.501
##
## Number of Fisher Scoring iterations: 7
myprobit_restricted <- glm(winner~nominations, data=oscar,
family=binomial(link="probit"))
summary(myprobit_restricted)##
## Call:
## glm(formula = winner ~ nominations, family = binomial(link = "probit"),
## data = oscar)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -4.57399 0.79345 -5.765 0.00000000818 ***
## nominations 0.44328 0.08728 5.079 0.00000037976 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 100.08 on 99 degrees of freedom
## Residual deviance: 60.70 on 98 degrees of freedom
## AIC: 64.7
##
## Number of Fisher Scoring iterations: 6
## Likelihood ratio test
##
## Model 1: winner ~ nominations + gglobes
## Model 2: winner ~ nominations
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 3 -22.75
## 2 2 -30.35 -1 15.199 0.00009676 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
核心问题:在已经知道了“奥斯卡提名数”的情况下,再去看“金球奖获奖数”还有意义吗?
中文通俗解读
这个似然比检验(LR test)好比是一场“留任面试”。
竞争对手: 全模型:使用提名数 + 金球奖数。 受限模型:只用提名数,把金球奖踢出去(假设 \(\beta_2 = 0\))。
比赛结果: 当你把金球奖这个变量扔掉后,模型的拟合程度(对数似然值)从 -22.75 掉到了 -30.35。 这个跌幅通过计算得出的卡方统计量是 15.199。 对应的 P 值是 0.00009676,这远小于 0.05。
在回归分析中,我们通常不是在问“B 厉不厉害”,而是在问:“在已经有了 A 的基础上,B 还能提供多少额外的新信息?” 只有把 A 留在模型里,再踢走 B,你观察到的“损失”才是纯粹由 B 提供的、A 替代不了的那部分价值。
结论: 金球奖不能被踢走。它提供了提名数之外的、非常关键的额外信息。换句话说,拿没拿过金球奖,对预测奥斯卡奖有非常显著的独立贡献。
English Version
To verify the hypothesis \(H_0: \beta_2 = 0\) (that the number of Golden Globes has no effect), we conducted a Likelihood Ratio (LR) test comparing the full model with a restricted model.
Conclusion: We reject the null hypothesis at the 0.1% significance level. There is strong evidence that the number of Golden Globes won is a statistically significant predictor of winning an Oscar, even after controlling for the number of nominations.
中文版
为了验证假设 \(H_0: \beta_2 = 0\)(即金球奖获奖数没有影响),我们进行了似然比检验(LR test),对比了全模型和剔除了金球奖变量的受限模型。
结论:我们在 0.1% 的显著性水平下拒绝原假设。这表明,在控制了提名数量之后,金球奖获奖数对于预测是否获得奥斯卡奖依然具有极显著的统计学意义。