Created
March 10, 2023 18:07
-
-
Save jebyrnes/8092951e43b15e75c2801d2e9dc648dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(piecewiseSEM) | |
make_tests <- function(){ | |
dat <- tibble( | |
x <- runif(100), | |
x1 = rnorm(100, x, sd = 0.001), | |
x2 = rnorm(100, x, sd = 0.001), | |
x3 = runif(100), | |
y1 = rnorm(100, x1 + x3, sd = 0.1), | |
y2 = rnorm(100, x2, sd = 0.1) | |
) | |
mod1 <- lm(y1 ~ x1 + x3, data = dat) | |
mod2 <- lm(y2 ~ x2, data = dat) | |
fit <- psem(mod1, mod2, data = dat) | |
cbind( | |
fisherC(fit), | |
LLchisq(fit) | |
) |> janitor::clean_names() |> as_tibble() | |
} | |
compare_tests <- purrr::map_df(1:1e3, ~make_tests()) | |
a <- compare_tests |> | |
mutate(match = (p_value>0.05) + (p_value_2>0.05), | |
match = !(match==1)) | |
#freq of match between fisher's c and ll chisq | |
sum(a$match)/nrow(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment