【发布时间】:2022-11-03 06:48:15
【问题描述】:
我想知道是否有可能在 R (即 RStudio)中做一个类似于这个的情节:
我估计的模型是:
library(MASS)
# with logit
mod1 <- polr(lifesatisfaction) ~ gender + age + income + education + health + work less + work much), data = surveywave5, method = "logistic", Hess = TRUE)
# with probit
mod1 <- polr(lifesatisfaction) ~ gender + age + income + education + health + work less + work much), data = surveywave5, method = "probit", Hess = TRUE)
# my data:
$ lifesatisfaction : Ord.factor w/ 11 levels "0"<"1"<"2"<"3"<..: 9 9 10 10 10 9 11 10 11 7 ...
$ gender : Factor w/ 2 levels "1","2": 2 1 1 1 1 1 2 1 2 1 ...
$ income : Factor w/ 10 levels "1","2","3","4",..: NA 2 4 5 5 10 7 7 6 3 ...
$ age : int 44 40 36 25 39 80 48 32 74 30 ...
$ education : Factor w/ 7 levels "1","2","3","4",..: 3 2 3 7 1 7 3 3 3 5 ...
$ health : Ord.factor w/ 5 levels "1","2","3","4",..: 3 4 1 3 4 5 5 4 4 3 ...
$ work less : Factor w/ 2 levels "0","1": 1 2 1 1 NA 1 1 1 2 1 ...
$ work much : Factor w/ 2 levels "0","1": 2 1 2 2 NA 1 2 2 1 2 ...
编辑*
我找到了这种方式..但是它似乎类似于 str().. 但不知道您是否可以将其用作可重现的:/
dput(head(surveywave5))
structure(list(gender = c(2, 1, 1, 1, 2, 2), maritalstatus = c(4, 6, NA, NA, 6, 6), age = c(62, 30, 44, 34, 58, 26), education = c(2, 7, 7, 7, 6, 4), lifesatisfaction = c(7, 8, 10, 7, 7, 8), health = c(4, 5, 5, 4, 5, 5), work.much = c(0, 1, 0, 0, 0, 0), work.less = c(1, 0, 1, 1, 1, 1), income = c(6, 1, 10, 6, 4, 1)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))
###编辑###
每条曲线代表模型中使用的每个 x 变量,像这样
所以,一条曲线代表年龄,一条曲线代表性别、健康、收入等。
【问题讨论】:
-
当然,这是可能的。你试过什么?此外,您更有可能通过可重现的示例获得帮助。你包含的数据的sn-p其实不是数据,而是数据结构的展示。您可以使用
dput(surveywave5)以可以粘贴到您的问题中的方式生成数据。 -
@DaveArmstrong 感谢您的评论!我想做一个可重现的例子,但我实际上不知道该怎么做。我认为 str() 就足够了。在我的情况下,使用 dput() 不是一个好的选择,因为我有超过 1200 次观察。我尝试了 dput 并且输出的输出太长,无法在这里分享。你有什么例子我可以给你一个可重复的例子吗? :/
-
@DaveArmstrong 我尝试使用 dput() 做另一件事 .. 不知道您是否可以将其用作可重现的示例。我知道您不想在没有看到我尝试过的情况下给出答案,但我真的不知道该怎么做。我找不到任何类似的例子。如果您可以提及包/库和功能,那么我可以自己尝试。
-
up..真的没有人可以帮忙吗?