这是从stats.stackexchange转发,我没有得到满意的答复。我有两个数据集,第一个在学校,第二个列出每个学校谁在标准化测试(强调故意)失败的学生。假数据集可以通过(感谢Tharen)产生:R:分层数据的贝叶斯逻辑回归
#random school data for 30 schools
schools.num = 30
schools.data = data.frame(school_id=seq(1,schools.num)
,tot_white=sample(100:300,schools.num,TRUE)
,tot_black=sample(100:300,schools.num,TRUE)
,tot_asian=sample(100:300,schools.num,TRUE)
,school_rev=sample(4e6:6e6,schools.num,TRUE)
)
#total students in each school
schools.data$tot_students = schools.data$tot_white + schools.data$tot_black + schools.data$tot_asian
#sum of all students all schools
tot_students = sum(schools.data$tot_white, schools.data$tot_black, schools.data$tot_asian)
#generate some random failing students
fail.num = as.integer(tot_students * 0.05)
students = data.frame(student_id=sample(seq(1:tot_students), fail.num, FALSE)
,school_id=sample(1:schools.num, fail.num, TRUE)
,race=sample(c('white', 'black', 'asian'), fail.num, TRUE)
)
我想估计P(失败= 1 |学生种族,学校收入)。如果我在学生数据集上运行多项式离散选择模型,我将明确地估计P(Race | Fail = 1)。我显然必须估计这个的倒数。由于所有信息都可以在两个数据集中获得(P(失败),P(竞赛),收入),我没有理由不能做到这一点。但是我很难理解如何在R中实现。任何指针都会非常感谢。谢谢。
文森特,谢谢你。父母收入表示,到学校级别的问题是,我不能包括额外的学生级别特征。这就是为什么我想要一个明确的分层估计逆概率的方法。 – user702432 2012-02-24 08:13:57
在这种情况下,我仍然建议将所有内容放在同一个data.frame (包括school_id,student_id,race,result,school_rev等), ,但是您还需要通过测试的学生的行。 – 2012-02-24 08:24:34
这就是问题所在。我在学生层面有一个截断的样本 - 这就是为什么我想要沿着混合建模的思路想一些东西。 – user702432 2012-02-24 08:28:38