【发布时间】:2021-02-26 04:11:52
【问题描述】:
当 parendiv 是我的因变量并且routine1997 是我的自变量时,我想进行回归,并将男性与女性进行比较。代码是这样的:
structure(list(gender = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L), .Label = c("male",
"female"), class = "factor"), parent = structure(c(2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("intact", "parentaldivorce"), class = "factor"),
routine = structure(c(1L, 1L, 1L, 1L, NA, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 3L), .Label = c("Med",
"High", "Low"), class = "factor")), row.names = c(3L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 16L, 18L, 19L, 21L, 22L, 23L, 24L,
25L, 28L, 29L, 30L, 34L), class = "data.frame")
这是代码,我想专门比较男女之间的系数。
lm(parent~routine, data=nlsy97, subset=gender)
【问题讨论】:
-
以性别作为虚拟变量拟合模型:
out <- lm(parent ~ routine + gender, data=nlsy97); summary(out)。然后查看性别的估计系数。
标签: r regression subset