Home > Back-end >  Adding a new variable with a code/formula that generates a moderate association with a previous one
Adding a new variable with a code/formula that generates a moderate association with a previous one

Time:03-13

I try adding a new variable that has an association with the previous one. Is there a math/code trick/formula to increase the width of confidence bands in this association?

library(tidyverse)

d = tibble(a = rnorm(50, 100, 20))

#adding a new variable that correlates with the previous
d = d %>% mutate(b = a*10) #<- this is the formula

#plotting association
d %>% ggplot(aes(a, b)) 
  geom_smooth(method = "lm")

enter image description here

CodePudding user response:

Something like this ?

d %>% 
mutate(b = a*10   rnorm(50, 0, 100)) %>%
ggplot(aes(a, b))   geom_smooth(method = "lm")       

enter image description here

  • Related