全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
14656 12
2015-01-07
在用glm进行logistic回归时,对于分类变量,需要设为哑变量,R中如何设置呢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-1-7 09:08:28
just set the variable as a factor, using as.factor(), or you can generate a factor variable by gl(). For more see, ?factor and ?gl
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-1-8 13:28:45
zngtian 发表于 2015-1-7 09:08
just set the variable as a factor, using as.factor(), or you can generate a factor variable by gl(). ...
好的,非常感谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-11-3 08:05:44
zngtian 发表于 2015-1-7 09:08
just set the variable as a factor, using as.factor(), or you can generate a factor variable by gl(). ...
但是用factor只能添加像gender这样的二值变量,怎么给多取值的categorical data添加哑变量呢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-11-6 11:06:16
八千美惠 发表于 2015-11-3 08:05
但是用factor只能添加像gender这样的二值变量,怎么给多取值的categorical data添加哑变量呢
factor()实际上生成多个dummy variables,如果你有三种情况,case = c(1, 2, 3), factor(case)就会以case=1为reference,生成两个dummy variables,case2, case3,这两变量会在回归结果里显示出来。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-11-11 17:21:15
如果是纯手动的话,可以ifelse(factor=="A",1,0)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群