Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function for returning estimates based on direction of confidence interval values

I have a dataframe with parameter estimates, the lower and upper 95% confidence interval from a local statistics model. I want to create a new column that returns the parameter estimates if the lower and upper confidence intervals are in the same direction (that is, when both are positive or negative) else a null or na. Using the table below as an example

enter image description here

I want a dataframe that looks like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

Here is a solution using dplyr, but of course you can use the same strategy based on ifelse with traditional variable assignment.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df <- tribble(~est, ~lci, ~uci,
              0.25, 0.12, 0.35,
              -0.36, -0.45, 0.01,
              -0.56, -0.62, -0.34)

df |> 
  mutate(SIG = ifelse(lci*uci>0, est, NA))
#> # A tibble: 3 × 4
#>     est   lci   uci   SIG
#>   <dbl> <dbl> <dbl> <dbl>
#> 1  0.25  0.12  0.35  0.25
#> 2 -0.36 -0.45  0.01 NA   
#> 3 -0.56 -0.62 -0.34 -0.56

Created on 2021-12-09 by the reprex package (v2.0.1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading