Recent Posts

Pages: 1 ... 8 9 [10]
91
Can someone share the class code of "Change of Varbile" in the example of phi(z) we did in the lecture? I got my result from code kind of inappropriate from the theretical value.

For now I get code like this:
g_2 <- function(x,z){
  return(z*exp(-((z*y)^2)/2))
}

y <- runif(M)
theta.2 <- mean(g_2(y,z))
Phi.2 <- 0.5 + theta.2/sqrt(2*pi)

Also could you also explain how this g_2 function come from?
Thank you ;)  ;)  ;)
92
Questions for R / RStudio (Spring 2023) / Re: Question for practice exam problem1
« Last post by Darth Knight on February 28, 2023, 05:28:22 pm »
Hi Cat,

I think the issue was in the inversion.
Please see the solution of the practice exam.


93
Questions for R / RStudio (Spring 2023) / Re: Question for practice exam problem1
« Last post by Cat on February 27, 2023, 06:46:15 pm »
I'm sorry Darth Knight, but I still cannot find the correct inverse function here.
I currently get the cdf to be F(x) = -exp[(-x^2)/16] + 1
And I always end up with the inverse function
f(x) = sqrt(-16*ln(1-x)) which does not make sense.
I guesss there exists some error on my integral but I do not know where it is... :-[  :-[  :-[
94
Questions for R / RStudio (Spring 2023) / Re: Question for practice exam problem1
« Last post by Darth Knight on February 27, 2023, 07:19:25 am »
Hi Cat,

The function looks okay, but we need to use the return() properly.
Since this is an inverse function the domain is between 0 and 1
and the range would be corresponding positive values.

95
Questions for R / RStudio (Spring 2023) / Re: Question for practice exam problem1
« Last post by Cat on February 27, 2023, 12:36:53 am »
Just make a correction, the function should be
 inv.fun <- function(x){
  result <- -log(1-x)
  return <- 4*sqrt(result)
}
but the domain is still confusing ???
96
Questions for R / RStudio (Spring 2023) / Question for practice exam problem1
« Last post by Cat on February 27, 2023, 12:33:11 am »
I'm quite confusing since I get an inverse function
inv.fun <- function(x){
  result <- -log(-x)
  return <- 4*sqrt(result)
}
like this. However, the domain of this function is all negative complex numbers which seems to be not correct.

I'm not sure if someone else get a different function or I should continue.

Thank you :)
97
Hi Cat,

Your observation is correct. c has to be greater than 1.

My question is whether g(x)=1 is really true.
I recommend you plot the g(x) first.
98
I am confusing about one case in the acceptance-rejection method:
we are required to find a constant c such that f(x)/g(x) < c
and for the probability for the acceptance value we have 1/c
Does this imply that we have to find the c > 1 since the probability cannot be greater than 1?

Just like Question 2 in our homework 5: I try to take g(x) = 1 and c = 0.65 but the theoretical probability value is 1/0.65 which seems to be unreasonable.
Or maybe I should try another g(x) and c in this case?
99
Hi Matt,

Yes, the discrete case of the inverse transformation method can be confusing.
The reason is that while the idea uses the inverse CDF,
we actually don't need to do the actual inversion for the implementation.

See the generation scheme on page 18 of Generating Random Variable I.
The algorithm does not use inverse CDF anywhere.

What we need to do is:
  • Find out the CDF values at the discontinuity points (in this case 0,1,2,3,...), and
    chop the interval (0,1) with those CDF values;
  • Generate u from uniform(0,1);
  • Track which sub-interval u falls into so that we can assign new random variables accordingly.

This procedure is actually what we did in our lab 9.
The sample code for logarithm distribution (we saw this on Tuesday) would be helpful
since the Poisson distribution is somewhat similar to the "logarithm" distribution (Both have infinite discontinuities.)

Please let me know if you need further clarification.
100
I am somewhat confused about how to calculate the inverse CDF of a discrete distribution. Could the inverse CDF of a Poisson distribution be calculated as the inverse of a normal distribution which approximates the Poisson distribution? Or is there a better method for approximating which amount of Poisson trials would produce a certain probability of success? Thank you!
Pages: 1 ... 8 9 [10]