I am using a case_when to run through a set of p.values and slopes to produce text describing the output. This thought approach has worked for me in the past, but now I am seeing some text output that is flat wrong. In the small example below you can see that p.values and slopes in records 1 and 3 should correspond to case_when situation 6 "there is strong evidence of a decreasing trend". Rather they are getting mapped to the default "the analysis did not run". My first instinct what the logic of the "strong evidence" conditionals are incorrect, but if it is, I am not seeing it.
Any insight would be much appreciated!
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 '
)
)