Recall that the Linear congruential generator is dened as Xn+1 = (aXn + b) mod m
ID: 3234264 • Letter: R
Question
Recall that the Linear congruential generator is dened as
Xn+1 = (aXn + b) mod m
Where a is our multiplier, b is our increment value, and m is our modulus value and determines the length of our sequence. Then we take this generated sequence of numbers and divide them by m to get a set of variates between 0 and 1. For this problem, pick your own values of a, b, and m and generate 10,000 variates using your random number generator.
Then do the following:
(a) Plot a histogram of your variates(In R):
(b) Draw the empirical CDF of your variates against the true CDF of a uniform distribution(In R).
(c) Perform the Kolmogorov-Smirnov test to validate your random number generator.(In R) Do your pseudorandom numbers seem to follow a uniform distribution? Base your conclusions from the test at an = 0.05.
Explanation / Answer
# Random Number from uniform Distribution
X<-runif(10000,min=0,max=1)
# Parameter Declaration
a<-3
b<-3
m<-3
#Model
Data<-((X*a+b) %% 3 )/3
Data
#Plots
hist(Data)
plot(ecdf(Data),col="red", main=NA)
lines(ecdf(X),col="green")
legend('right', c('Data', 'X'), fill=c("red", "green"), border=NA)
#Kolmogorov-Smirnov test
ks.test(Data,X)
From the test we can conclude that our generated number follow uniform distribution.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.