How I could solve this exercise:
Let U come from a uniform (0,1) distribution and Z come from a standard normal distribution. Let X = pZ + (1-p)U. Estimate p when X has a variance of 0.4.
Maybe I should install.packages('polynom')?
p is equal to 0,62 because I´ve already calculated it analitically, but I don´t know how to solve it with R using random random numbers generators
Here is an example
fobj <- function(p) abs(var(p*rnorm(1e5) + (1-p)*runif(1e5))-0.4)
pval <- optimise(fobj,c(0,1))$minimum
where
fobj
, i.e., distance between variance of X
and 0.4
optimise
minimize the fobj
Result
> pval
[1] 0.6223968