Question

In: Statistics and Probability

Write a function to generate random variates from a Lognormal(mu, sigma) distribution using a transformation method,...

Write a function to generate random variates from a Lognormal(mu, sigma) distribution using a transformation method, and generate a random sample size of 1000 in R. Compare the histogram with the lognormal density curve given by dlnorm function in R.

Solutions

Expert Solution

Inverse Transform method:

If has distribution, then such that is an observation from the probability distribution , this means that we can generate observations from the distribution by generating random variables (which most software programs can do easily) and applying the transformation.

Here  .

The CDF is

Now, .

The R code for generating 1000 log normal random variables with and plotting the histogram and density is given below:

n <- 1000
U <- runif(n)
mu <- 0.3
sigma <- 0.25
X <- array (dim =n)
for (i in 1:n)
{
X[i] <- exp(mu+sigma*qnorm(U[i]))
}
plot(1:1)
dev.new()
hist(X,prob =TRUE, ylim=c(0,1.2),col = "skyblue", main = "Histogram of Lognormal Distribution")
curve(dlnorm(x,meanlog=mu,sdlog=sigma),col="blue",lwd=2,add=TRUE)

The plots are:


Related Solutions

Write a function that will generate an array of random numbers. It needs to:
DO IN C++Write a function that will generate an array of random numbers. It needs to:Take 3 integers as parameters-The first is the minimum value-the second is the maximum value-the third is the size of the new array-create a dynamically allocated array of the correct size-generate a random number (between min and max) for each element in the array-return a pointer to the arrayCreate a main() function that tests the above function and displays the values in the random array.
For a random sample of size 64 from a population with mu=24 and standard deviation sigma=1.5....
For a random sample of size 64 from a population with mu=24 and standard deviation sigma=1.5. State the center, variation, and shape of the sampling distribution for samples of size 64. Justify your answer. Find the probability that the sample mean exceeds 24.3. Draw a fully labeled picture that illustrates the probability, and write down your answer using probability notation.
Derive the variance of a normal distribution with mean Mu and standard deviation Sigma.
Derive the variance of a normal distribution with mean Mu and standard deviation Sigma.
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution...
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution between -0.5 and 0.5, and find the mean of these 10 numbers. Consider this mean to be the ‘result’ of this procedure. b) Repeat this 10 times and calculate the mean and variance of your 10 results. Is the distance of the mean from 0 about what you would expect? Why? c) Now repeat it 100 times and calculate the mean and variance. Is...
The language is MATLAB Write a function that will generate three random integers, each in the...
The language is MATLAB Write a function that will generate three random integers, each in the inclusive range from 10 to 80. It will then return a string consisting of the three integers joined together, and also a character vector consisting of the three integers joined together. For example, if the random integers are 11, 29, and 76, the string that is returned will be "112976" and the character vector that is returned will be '112976'. I'm really confused on...
X follows a normal distribution with mu = 4.7 and sigma = 1.1. P(3.05 < X...
X follows a normal distribution with mu = 4.7 and sigma = 1.1. P(3.05 < X < 3.93) to four decimal places is: 1) 0.6752 2) 0.1752 3) 0.3248 4) 0.8248
The population of IQ scores forms a normal distribution with mu equals space 100 and sigma...
The population of IQ scores forms a normal distribution with mu equals space 100 and sigma space equals space 15. If you take a random sample of 25 people who have taken the IQ test, what is the probability of obtaining a sample mean greater than M = 94?
Generate 1000 random numbers from a normal distribution with mean 1 and variance 2 using Box‐Muller...
Generate 1000 random numbers from a normal distribution with mean 1 and variance 2 using Box‐Muller transformation in R.
Write a program that uses a custom function to generate a specified number of random integers...
Write a program that uses a custom function to generate a specified number of random integers in a specified range. This custom function should take three arguments; the number of integers to generate, the lower limit for the range, and the upper limit for the range. Values for these arguments should be entered by the user in main. The custom function should display the random integers on one line separated by single spaces. The function should also report how many...
Giving a normal distribution with mean mu=40 and standard deviation sigma = 10 where the probability...
Giving a normal distribution with mean mu=40 and standard deviation sigma = 10 where the probability that x0<x<x1 = 0.9. What is the Total Area to the left for x1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT