I wrote down the code for an inversion sampler to generate a sample of N = 1000 random numbers from the Pareto distribution with a = 2 and b = 3. Use the generated CNRG pseudo-random numbers.
Xo<-33475781
a<-3
c<-5
m<-1000
U <- numeric(length = m)
U[1]<-Xo
for(i in 2:m){
U[i] <- (a*U[i-1]+c)%%m
}
inv<-function(U,A,b) {
A/((U)^(1/b))
}
pareto<-inv(U,A=2,b=3)
and then Draw a histogram for the generated sample and add a line with the true density of the Pareto(2, 3) distribution, but the density line doesn't show up on the graph.
hist(pareto, col = "tomato", freq = FALSE)
A=2
b=3
den<-function(U,A,b) {
b*((A^b)/(U^(b+1)))
}
xcoord = seq(0, 1, length=1000)
ycoord = den(xcoord, A, b)
lines(xcoord,ycoord,
col="blue",
lwd=6)
if I change ycoord = den(U, A, b) instead,
then there's only a straight line in the bottom.
How can I fix the problem?
Thank you