R 自分组数据的logistic回归模型拟合
我最初有一组未分组的数据,我将其转换为Catergoric(关于列职业),现在我想用逻辑回归模型来拟合我创建的数据,“成功”由每个职业类别中死亡的人数表示 使用的数据和数据分组 任何分组之前的初始数据集如下所示:R 自分组数据的logistic回归模型拟合,r,R,我最初有一组未分组的数据,我将其转换为Catergoric(关于列职业),现在我想用逻辑回归模型来拟合我创建的数据,“成功”由每个职业类别中死亡的人数表示 使用的数据和数据分组 任何分组之前的初始数据集如下所示: Occupation Education Age Died 1 household Secondary 39 no 2 farming primary 83 yes 3 farming primary 60 yes 4 farming p
Occupation Education Age Died
1 household Secondary 39 no
2 farming primary 83 yes
3 farming primary 60 yes
4 farming primary 73 yes
5 farming Secondary 51 no
6 farming iliterate 62 yes
然后,我使用以下方法对数据进行分组:
occu %>% group_by(Occupation, Died) %>% count()##use this to group on the occupation of the suicide victimrs
这将导致以下输出:
Occupation Died n
<fct> <fct> <int>
1 business/service no 12
2 business/service yes 9
3 farming no 939
4 farming yes 1093
5 household no 154
6 household yes 94
7 others yes 3
8 others/unknown no 146
9 others/unknown yes 10
10 professional no 11
11 professional yes 26
12 retiree no 3
13 student no 27
14 student yes 8
15 unemployed no 23
16 unemployed yes 7
17 worker yes 6
其输出:
ccupation Died n total prop
<fct> <fct> <int> <int> <dbl>
1 business/service no 12 21 0.571
2 business/service yes 9 21 0.429
3 farming no 939 2032 0.462
4 farming yes 1093 2032 0.538
5 household no 154 248 0.621
6 household yes 94 248 0.379
7 others yes 3 3 1
8 others/unknown no 146 156 0.936
9 others/unknown yes 10 156 0.0641
n总道具占用率
1商业/服务编号12 21 0.571
2业务/服务是9 21 0.429
3农业编号939 2032 0.462
4农业是1093 2032 0.538
5户1542480.621
6住户是94 248 0.379
7其他3 3 1
8其他/未知编号146 156 0.936
9其他/未知是10 156 0.0641
问题
我的问题是,如何使用原始模型中的所有三个预测因子(教育、年龄、分组职业),对分组数据运行逻辑回归模型,死亡=是成功,否=失败。从编程角度看,您可以看到。从统计上讲,我认为你的方法不正确,即先做计数,然后做总计,谢谢你的输入,我会查看链接,我很关心这个方法,你对尝试解决这个问题有什么建议吗?我会直接将死亡的LR作为年龄的函数,只需注意
其他人
,因为它没有无
类别,所以您可能需要将其与其他人/未知
组合。如果在每个类别中有足够的样本大小用于<代码>教育<代码>,那么您可以考虑将<代码>教育> /代码>添加到模型中。最后,确定死亡是一个因子类型,<代码>没有<代码>是参考级别,或者从编程的角度将其转换为0=死亡和1=Yes,您可以看到。从统计上讲,我认为你的方法不正确,即先做计数,然后做总计,谢谢你的输入,我会查看链接,我很关心这个方法,你对尝试解决这个问题有什么建议吗?我会直接将死亡的LR作为年龄的函数,只需注意其他人
,因为它没有无
类别,所以您可能需要将其与其他人/未知
组合。如果在每个类别中有足够的样本大小用于<代码>教育<代码>,那么您可以考虑将“代码>教育/代码>添加到模型中。最后,确定死亡是一个因子类型,<代码>没有<代码>是参考级别,或者将其转换为0=死亡和1=是。
ccupation Died n total prop
<fct> <fct> <int> <int> <dbl>
1 business/service no 12 21 0.571
2 business/service yes 9 21 0.429
3 farming no 939 2032 0.462
4 farming yes 1093 2032 0.538
5 household no 154 248 0.621
6 household yes 94 248 0.379
7 others yes 3 3 1
8 others/unknown no 146 156 0.936
9 others/unknown yes 10 156 0.0641