一段时间以来,我一直在这里摸不着头脑,我真的不知道在 ggforest 中处理 hr 地块时我的因素有什么问题。
从第一张图片可以看出,教育变量中有一个参考值,其他值有危险风险,完美!
问题是因子水平的名称很短而且信息量不大,所以我当然想更改名称,以便您了解它们的含义。但是,现在除了“未知”之外的所有值都成为参考值,但我所做的只是更改名称(我希望如此)。
首先,我认为使用长名称或其他东西可能存在问题,但我用一些假数据尝试了同样的事情,完全没有问题。
library(survminer)
library(tidyverse)
n <- 200
m <- 6
p <- round(runif(n,4,m))
dat <- data.frame(id=rep(1:n, times=p))
gendertable <- data.frame(id = unique(dat$id), gender = sample(0:1, length(unique(dat$id)), replace = T))
birthtable <- data.frame(id = unique(dat$id), birth_year = sample(c(1960, 1970, 1980, 1990), length(unique(dat$id)), replace = TRUE))
dat <- dat %>%
mutate(pain_lvl = sample(c(4, 3, 2, 1),
size = nrow(dat), prob = c(0.2, 0.2, 0.25, 0.35), replace = TRUE))
dat <- merge(gendertable, dat)
dat <- merge(birthtable, dat)
dat <- dat %>%
group_by(id) %>%
mutate(period = row_number())
dat$start <- dat$period - 1
dat$stop <- dat$period
dat <- dat %>%
group_by(id) %>%
mutate(event = ifelse(stop == n() & stop < 5, 1, 0))
dat$birth_year <- as.factor(dat$birth_year)
dat$gender <- as.factor(dat$gender)
dat <- dat %>%
mutate(gender.factor = recode(as.factor(gender),
`0` = "Male",
`1` = "Female")) %>%
mutate(pain_lvl.factor = recode(as.factor(pain_lvl),
`1` = "Very low-level",
`2` = "Medium-level",
`3` = "High-level",
`4` = "Very High very high indeed"))
model <- coxph(Surv(start, stop, event) ~ birth_year + gender.factor + pain_lvl.factor,
ties = c("efron"),
data = dat)
ggforest(model)
那么问题是植根于我的数据而不是 ggforest 还是我犯了其他错误?如果有人可以查看我的数据并希望了解问题所在,我将非常感激。链接:https : //easyupload.io/0fo866 csv文件
我使用以下代码来读取表格、转换因子、重新编码值等。
library(survial)
library(survminer)
library(tidyverse)
dat <- read.table("~/dat.csv", header = TRUE, sep = ";")
dat[dat==""]<-NA
dat <- dat %>%
mutate(education = recode(education,
"low" = "Low-level education",
"middle" = "Mid-level education",
"high" = "High-level education"))
dat <- dat %>%
mutate(education = ifelse(is.na(education), "Unknown", education))
dat <- dat %>%
mutate(female.factor = recode(as.factor(female),
`0` = "No",
`1` = "Yes"))
dat <- dat %>%
mutate(education.factor = as.factor(str_to_sentence(education)))
dat <- dat %>%
mutate(birth_year.factor = (as.factor(birth_year)))
model1 <- coxph(Surv(start, stop, event) ~ birth_year.factor + female.factor + education.factor + frailty(id),
ties = c("efron"),
data = dat)
ggforest(model1)