gpt4 book ai didi

r - 尝试运行固定效应逻辑回归时出错

转载 作者:行者123 更新时间:2023-12-01 04:46:31 26 4
gpt4 key购买 nike

不知道从哪里可以获得帮助,因为这篇确切的帖子在 StackExchange 上被认为是题外话。

我想基于平衡面板进行一些回归,其中包含来自巴西的选举数据,重点是 2 个时间段。 I want to understand if after a change in legislation that prohibited firm donations to candidates, those individuals that depended most on these resources had a lower probability of getting elected.

我已经在 R 上进行了这样的回归:

model_continuous <- plm(percentage_of_votes ~ time + 
treatment + time*treatment, data = dataset, model = 'fd')

在这个模型上,我使用了一个连续变量(投票百分比)作为我的因变量。我的 treatment单位或 time = 0 中的单位没有来自公司的竞选捐款。

Now I want to change my dependent variable so that it is a binary variable indicating if the candidate was elected on that year. All of my units were elected on time = 0 .我如何估计 logitprobit模型使用固定效应?我曾尝试使用 pglm R中的包。
model_binary <- pglm(dummy_elected ~ time + treatment + time*treatment, 
data = dataset,
effects = 'twoways',
model = 'within',
family = 'binomial',
start = NULL)

但是,我收到此错误:
Error in maxRoutine(fn = logLik, grad = grad, hess = hess, start = start,  : 
argument "start" is missing, with no default

为什么会这样?我的模型有什么问题?它在概念上是否正确?
我希望第二个回归与第一个回归尽可能相似。

我读过 clogit来自 survival 的函数包可以完成这项工作,但我不知道该怎么做。

编辑 :

这是示例数据集的样子:
dataset <- data.frame(individual = c(1,1,2,2,3,3,4,4,5,5),
time = c(0,1,0,1,0,1,0,1,0,1),
treatment = c(0,0,1,1,0,0,1,1,0,0),
corporate = c(0,0,0.1,0,0,0,0.5,0,0,0))

最佳答案

根据评论,我相信逻辑回归可以简化为治疗和 dummy_elected。因此,我制作了以下数据集:

dataset <- data.frame("treatment" = c(rep(1,1000),rep(0,1000)),
"dummy_elected" = c(rep(1, 700), rep(0, 300), rep(1, 500), rep(0, 500)))

然后我运行了 GLM 模型:
library(MASS)
model_binary <- glm(dummy_elected ~ treatment, family = binomial(), data = dataset)
summary(model_binary)

注意处理系数是显着的,系数是给定的。由此产生的概率是
Probability(dummy_elected) = 1 =>  1 / (1 + Exp(-(1.37674342264577E-16 + 0.847297860386033 * :treatment)))
Probability(dummy_elected) = 0 => 1 - 1 / (1 + Exp(-(1.37674342264577E-16 + 0.847297860386033 * :treatment)))

请注意,这些概率与我生成数据的频率一致。

所以对于每一行,取上面两个方程的最大概率,这就是 dummy_elected 的值。

关于r - 尝试运行固定效应逻辑回归时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46186420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com