Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Densities This is the (small) population of patients with a rare disease, along with where they live: Name City Nana Alpharetta Nia Alpharetta Anya Alpharetta
Densities
This is the (small) population of patients with a rare disease, along with where they live:
Name | City |
Nana | Alpharetta |
Nia | Alpharetta |
Anya | Alpharetta |
Yamiaya | Atlanta |
Youssef | Atlanta |
Ibrahim | Alpharetta |
Lizelle | Buckhead |
Chen | Atlanta |
Carlos | Buckhead |
Jin | Buckhead |
Rachael | Alpharetta |
Lukas | Alpharetta |
Olivia | Atlanta |
Ayesha | Buckhead |
Fatima | Buckhead |
A) Come up with the density R function for "city " in this population.
B. The function (equivalent to or) that draws samples from a "population" that has a variable X that has this density. You don't have to understand how this code works, but if you're curious, all it does is pick a number between 1 and 3 and depending on what it is it samples from one of three different normal distributions.
r_mydensity=function(n){ df = tibble(
S = sample(1:3, size=n, replace=T),
X = case_when(
S==1~rnorm(n,mean=-5,sd=1), S==2 ~ rnorm(n, mean = 0, sd = 2), S==3~rnorm(n,mean=5,sd=1.5)
)
) %>% pull(X)
}
sample = r_mydensity(1000)
hist(sample)