我正在使用case_when来遍历一组p.value和斜率以生成描述输出的文本。这种思想方法过去对我有用,但是现在我看到一些文本输出完全错误。在下面的小示例中,您可以看到记录1和3中的p。值和斜率应与case_when对应,当情况6“有强有力的证据表明趋势下降时”。而是将它们映射到默认的“分析未运行”。我的第一个直觉是“强力证据”条件的逻辑是不正确的,但如果是这样,我看不到它。
任何见识将不胜感激!
tb <- tibble(id = 1:6,
pvalue = c(2.82E-09, 0.157357748, 7.39E-10, 0.020180304, 0.563924231, 0.457426386),
slope = c(-2.083380271, -2.289794628, -0.593972568, 0.520946683, -0.38796253, -0.715571944)
)
new_tb <- tb %>%
mutate(
text = case_when(
pvalue <= 0.01 & slope > 0 ~ ' there is strong evidence of an increasing trend ',
pvalue > 0.01 & pvalue <= 0.05 & slope > 0 ~ ' there is evidence of an increasing trend ',
pvalue > 0.05 & pvalue <= 0.10 & slope > 0 ~ ' there is evidence of a possible increasing trend ',
pvalue > 0.10 & pvalue <= 0.20 & slope > 0 ~ ' there is weak evidence of an increasing trend ',
pvalue > 0.2 ~ ' there is no evidence of a detectable trend ',
pvalue <= 0.01 & pvalue < 0 ~ ' there is strong evidence of a decreasing trend ',
pvalue > 0.01 & pvalue <= 0.05 & slope < 0 ~ ' there is evidence of a decreasing trend ',
pvalue > 0.05 & pvalue <= 0.10 & slope < 0 ~ ' there is evidence of a possible decreasing trend ',
pvalue > 0.10 & pvalue <= 0.20 & slope < 0 ~ ' there is weak evidence of a decreasing trend ',
TRUE ~ ' the analysis did not run '
)
)