我试图在R中拟合logistic回归,其中我的反应是学生是否处于缓刑状态,我的六个自变量是:
x1 = gender(male,female) which is nominal.
x2 = Hour spend in family activity (0 hour, <5 hour, 5-9 hour, 10-14 hour,
>14 hour)
x3 = number of times under probation
x4 = types of school(public, private, other)
x5 = level of attendance in class( 70%, 70-79%, 80-89%, 90-99%, 100%)
x6 = hours of library work (0 hour, <5 hour, 5-9 hour, 10-14 hour, >14 hour)
我的问题是,我有名义和序数的混合,谁能帮助适应这个模型在R?
发布于 2022-09-11 07:33:51
只需将变量转换为所需的每一种类型,在这种情况下:
x1 = factor(x1, levels = c("male", "female")) #nominal
x2 = factor(x2, levels = c("0 hour", "<5 hour", "5-9 hour", "10-14 hour",
">14 hour"), ordered = TRUE) #ordinal
x3 #stay_numeric
x4 = factor(x4, levels = c("public", "private", "other")) #nominal
x5 = factor(x5, levels = c("70%", "70-79%", "80-89%", "90-99%", "100%"),
ordered = TRUE) #ordinal
x6 = factor(x6, levels = c("0 hour", "<5 hour", "5-9 hour", "10-14 hour", ">14 hour"), ordered = TRUE) #ordinal
然后可以使用glm
库将这些变量匹配到模型中,它将自动扩展变量的级别或类别。
https://stackoverflow.com/questions/57656217
复制相似问题