Open vasishth opened 4 months ago
Source: https://statmodeling.stat.columbia.edu/2024/04/14/simulation-to-understand-measurement-error-in-regression/#comment-2359176
library(tidyverse) set.seed(123) n <- 1000 a <- 0.2 b <- 0.3 sigma <- 0.5 fake % mutate(y_star = rnorm(n, y, sigma_y), x_star = rnorm(n, x, sigma_x)) bind_rows( tibble(x=fake$x, y=fake$y, name=”No measurement error”), tibble(x=fake$x, y=fake$y_star, name=”Measurement error on y”), tibble(x=fake$x_star, y=fake$y, name=”Measurement error on x”), tibble(x=fake$x_star, y=fake$y_star, name=”Measurement error on x and y”) ) %>% mutate(name = fct_inorder(name)) %>% ggplot(aes(x,y)) + geom_point() + geom_smooth(method=”lm”, fullrange=TRUE) + facet_wrap(~name)
Source: https://statmodeling.stat.columbia.edu/2024/04/14/simulation-to-understand-measurement-error-in-regression/#comment-2359176