Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the default of adjust_coef_with_binary() adjust linear model coef #12

Merged
merged 10 commits into from
Oct 14, 2022
Merged

make the default of adjust_coef_with_binary() adjust linear model coef #12

merged 10 commits into from
Oct 14, 2022

Conversation

malcolmbarrett
Copy link
Contributor

library(tipr)
# IPW estimates without unmeasured confounder 
estimates <- c(estimate = -12.5, conf.low = -13.8, conf.high = -11.3)

adjust_coef_with_binary(
  estimates, 
  exposed_confounder_prev = 0.25, 
  unexposed_confounder_prev = .05, 
  confounder_outcome_effect = -8
)

#> # A tibble: 3 × 5
#>   effect_adjusted effect_observed exposed_confounder_prev unexposed_co…¹ confo…²
#>             <dbl>           <dbl>                   <dbl>          <dbl>   <dbl>
#> 1          -10.2            -12.5                    0.25           0.05      -8
#> 2          -11.5            -13.8                    0.25           0.05      -8
#> 3           -9.03           -11.3                    0.25           0.05      -8
#> # … with abbreviated variable names ¹​unexposed_confounder_prev,
#> #   ²​confounder_outcome_effect

Created on 2022-09-23 with reprex v2.0.2

@LucyMcGowan
Copy link
Collaborator

perfect! also make sure to add yourself to the description 🎉

@malcolmbarrett
Copy link
Contributor Author

Added myself as contributor ✅

Oops! It is actually way simpler than I thought, just rederived, it should just be the difference in prevalences between the groups.
@LucyMcGowan
Copy link
Collaborator

LucyMcGowan commented Sep 24, 2022

@malcolmbarrett I rewent through the math this morning and realized it simplifies to basically the same equation as adjust_coef for the normally distributed case -- for linear regression it is just the difference in prevalences! This exercise actually led me down a rabbit hole that led me to looking this up in linear regression textbook which shows that we basically don't need any of our assumptions of independence of other confounders in the model (just additivity, so no interactions between unmeasured confounder and the outcome) and we can calculate the impact of the confounder using this:

image

I wonder if we should have totally separate functions for linear models since they are so much cleaner?

@malcolmbarrett
Copy link
Contributor Author

malcolmbarrett commented Sep 24, 2022

Interesting. re: your first point, similar but not exactly the same as is. This is what you meant, yeah?

library(tipr)
# IPW estimates without unmeasured confounder 
estimates <- c(estimate = -12.5, conf.low = -13.8, conf.high = -11.3)

x <- adjust_coef_with_binary(
  unlist(estimates), 
  exposed_confounder_prev = 0.25, 
  unexposed_confounder_prev = .05, 
  confounder_outcome_effect = -8
)

y <- adjust_coef(
  unlist(estimates), 
  exposure_confounder_effect = 0.25 - .05, 
  confounder_outcome_effect = -8
)

tibble::tibble(x = x$effect_adjusted, y = y$effect_adjusted)
#> # A tibble: 3 × 2
#>        x     y
#>    <dbl> <dbl>
#> 1 -10.2  -10.9
#> 2 -11.5  -12.2
#> 3  -9.03  -9.7

Created on 2022-09-24 with reprex v2.0.2

@LucyMcGowan
Copy link
Collaborator

LucyMcGowan commented Sep 24, 2022 via email

@malcolmbarrett
Copy link
Contributor Author

That makes sense (and the two are identical when I use the updated code)! Ok, I tweaked it a little. This is a little silly, but I switched it to call adjust_coef() internally because that's intuitive to me. I also mentioned in the docs that they are the same in that case.

Regarding your second point re: assumptions, that only affects the interpretation, correct? If that's the case, I think we should mention it in the docs (and book chapter) but that they don't need to be separated out

@LucyMcGowan
Copy link
Collaborator

I don't think that is silly! In fact maybe that is what we should kind of push people towards because that one fits a bit better under any scenario. I'm not sure the best way to word the docs now, but basically exposure_confounder_effect could be the difference in means for a Normally distributed confounder with a variance of one OR it could be the beta coefficient for the exposure (X) from this model:

U ~ X + Z

where Z are the other measured confounders -- with this U can be any distribution AND need not be independent from Z so way easier 😂

@LucyMcGowan
Copy link
Collaborator

LucyMcGowan commented Sep 25, 2022

image

I've updated here in the last section

@LucyMcGowan LucyMcGowan merged commit 9fb5eb4 into r-causal:master Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants