admin管理员组文章数量:1333168
I am trying to fit a very simple logistic regression model on a data, and then try and get an easystats text report:
library(tidyverse)
library(easystats)
Data <- structure(list(`12_month_remission` = c(0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0,
1), Sex = structure(c(2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L,
1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), levels = c("Female", "Male"), class = "factor")), row.names = c(NA,
-50L), class = c("tbl_df", "tbl", "data.frame"))
glm(`12_month_remission` ~ Sex, family = "binomial", data = Data) %>%
report::report()
And its coming up with:
Error in eval(predvars, data, env) : object '12_month_remission' not found Error: Unable to refit the model with standardized data.
Try instead to standardize the data (standardize(data)) and refit the model manually.
I know the model fit works, as if I just run the script without the report() I get an output. It doesnt make sense to Z-normalise data.. because there is no data that can be standardized? What am I missing?
I am trying to fit a very simple logistic regression model on a data, and then try and get an easystats text report:
library(tidyverse)
library(easystats)
Data <- structure(list(`12_month_remission` = c(0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0,
1), Sex = structure(c(2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L,
1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), levels = c("Female", "Male"), class = "factor")), row.names = c(NA,
-50L), class = c("tbl_df", "tbl", "data.frame"))
glm(`12_month_remission` ~ Sex, family = "binomial", data = Data) %>%
report::report()
And its coming up with:
Error in eval(predvars, data, env) : object '12_month_remission' not found Error: Unable to refit the model with standardized data.
Try instead to standardize the data (standardize(data)) and refit the model manually.
I know the model fit works, as if I just run the script without the report() I get an output. It doesnt make sense to Z-normalise data.. because there is no data that can be standardized? What am I missing?
Share Improve this question edited Nov 20, 2024 at 20:42 zx8754 56.3k12 gold badges125 silver badges225 bronze badges Recognized by R Language Collective asked Nov 20, 2024 at 15:25 Rover EyeRover Eye 2491 silver badge13 bronze badges2 Answers
Reset to default 5You're running into trouble because the name of your response variable isn't a legal R variable name. That's allowed (you just have to include it in ``, as you've already done), but in some cases (as you have found out) it causes problems downstream. Best practice would generally be to rename the variable to something not starting with a digit, e.g.
Data <- Data |> rename(remission = "12_month_remission")
m <- glm(remission ~ Sex, family = "binomial", data = Data)
report::report(m)
In slight contrast to @JilberUrbina's answer, which makes the same point, I would suggest doing this renaming as part of the initial 'data cleaning' section of your workflow where you do things like make sure that all variables have the required types (numeric vs categorical/factor), that factors have the right levels in a sensible order, etc., rather than doing it as part of a one-off pipe into glm()
...
It is about a matter of name in 12_month_remission
. The easiest way to solve it is changing the name and it'll run
Data %>%
rename(remission_12_months = "12_month_remission") %>%
glm(remission_12_months ~ Sex, family = binomial, data = .) %>%
report::report()
We fitted a logistic model (estimated using ML) to predict remission_12_months with Sex (formula: remission_12_months ~ Sex). The model's
explanatory power is weak (Tjur's R2 = 0.13). The model's intercept, corresponding to Sex = Female, is at 0.07 (95% CI [-0.69, 0.84], p =
0.847). Within this model:
- The effect of Sex [Male] is statistically significant and negative (beta = -1.63, 95% CI [-3.06, -0.38], p = 0.015; Std. beta = -1.63, 95% CI
[-3.06, -0.38])
Standardized parameters were obtained by fitting the model on a standardized version of the dataset. 95% Confidence Intervals (CIs) and p-values
were computed using a Wald z-distribution approximation.
本文标签: rVariable names and Easystats reportsStack Overflow
版权声明:本文标题:r - Variable names and Easystats reports - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742349461a2458191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论