我正在进行逻辑回归分析,以通过多个连续变量来预测分类变量(性别)。但是,我遇到一些错误,真的需要有人帮助我。
在这里放置仿真数据和代码。
library(tidyverse)
library(broom)
library(purrr)
data <- data.frame(cat = rep(c("A", "B", "C", "D"), each = 20),
shar = rep(c("fr", "bs"), each = 20),
sex = rep(c("f", "m"), each = 20),
bmi = runif(20, min = 0, max = 30),
fbg = runif(20, min = 70, max = 140),
AB = runif(20, min = 0, max = 1),
Ac = runif(20, min = 0, max = 1),
Ad = runif(20, min = 0, max = 3),
Ae = runif(20, min = 0, max = 4),
Af = runif(20, min = 2, max = 4),
Ba = runif(20, min = 2, max = 10),
Bb = runif(20, min = 10, max = 40),
Bc = runif(20, min = 5, max = 50),
BD = runif(20, min = 0.5, max = 1),
BF = runif(20, min = 5, max = 10),
Ca = runif(20, min = 2, max = 10),
Cb = runif(20, min = 10, max = 40),
Cc = runif(20, min = 5, max = 50),
CD = runif(20, min = 0.5, max = 1),
CF = runif(20, min = 5, max = 10))
data1 <- data %>%
gather(Fac, value, -cat:-sex) %>%
split(.$Fac) %>%
map(~glm(sex ~ value,family = binomial(link = "logit"), data =.) %>%
tidy(.) %>%
select(estimate, std.error,statistic,p.value) %>%
slice(2)) %>%
bind_rows(.id = "variables")
这是错误
eval(family $ initialize)中的错误:y值必须为0 <= y <= 1。
然后,我按原样修改了代码,但仍然出现错误
data$gendr <- ifelse(data$sex =="m",1L,0L)
data1 <- data %>%
gather(Fac, value, -cat:-sex) %>%
split(.$Fac) %>%
map(~glm(gendr ~ value,family = binomial(link = "logit"), data =.) %>%
tidy(.) %>%
select(estimate, std.error,statistic,p.value) %>%
slice(2)) %>% ## Extracting regression of genes
bind_rows(.id = "varaibles")
错误是
eval(predvars,data,env)中的错误:找不到对象'gendr'
谢谢!