-1

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

Andrea Garcia
  • 127
  • 2
  • 8

2 Answers2

2

I will not solve for you the exercice but give you the clue on how to solve it

You need to do as the exercice does:

  1. Simulate U[0,1]
  2. Simulate N(0,1)

Put them together using a value for p

For a given p, you can define a function:

set.seed(234)
computeX <- function(p){

  u <- runif(1000)
  z <- rnorm(1000)

  X = p*z + (1-p)*u
  return(X)
}

var(computeX(0.2))
[1] 0.08924463

Now I let you find the routine to get p that is needed for your exercice.

No need for any external library

linog
  • 5,786
  • 3
  • 14
  • 28
  • 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 – Andrea Garcia Apr 19 '20 at 17:47
1

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

  • first define your objective function fobj, i.e., distance between variance of X and 0.4
  • then apply optimise minimize the fobj

Result

> pval
[1] 0.6223968
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81