I am trying to create a qqplot and run a KS test for a normal mixture distribution with 25% N(μ=0,σ=4) and 75% N(μ=4,σ=2). How could I adapt my qqplot and KS test for this distribution? I don't think my abline is correct and my KS test doesn't really reflect the distribution correctly.
Any help would be appreciated.
set.seed(4711)
n = 500
P = ppoints(n)
Q = qnorm(P)
dt <- sample(c(1,2), prob= c(0.25,0.75), size = n, replace = T)
x <- c()
for(i in 1:n){
if(dt[i] == 1) x[i]=rnorm(1, mean = 0, sd = 4) else x[i] = rnorm(1, mean = 4, sd = 2)
}
hist(x, prob = T, breaks = 27, col = "lightgreen", main = "Mixture Normal")
curve(0.25*dnorm(x, mean = 0, sd = 4) + 0.75*dnorm(x, mean = 4, sd = 2), add = T, col = 2, lwd = 3, lty = 2)
qqplot(Q, x)
abline(0,1)
ks.test(x, 'pnorm')