Professional Documents
Culture Documents
Assignment 2
Assignment 2
Andres Gonzalez
2024-03-01
# By using the file NormalDist in R, research on how to use the Kolmogorov Smirnoff goodness of
fit procedure to test if a set of data accomplishes a normal distribution or not. You will need
to create an empirical data set through a random variate generator, like the one covered in clas
s using polar coordinates.
# Function to generate two independet standard normal random variables using the polar method
set.seed(42)
n <- 100
generate_normal_polar <- function() {
repeat {
U1 <- runif(1, 0, 1)
U2 <- runif(1, 0, 1)
V1 <- 2 * U1 - 1
V2 <- 2 * U2 - 1
S <- V1^2 + V2^2
if (S <= 1) {
break
}
}
return(c(X1, X2))
}
norm[1:20]
## [1] -0.53150173 0.82125270 2.21744970 0.29873471 0.40485862 -0.62517195
## [7] 0.98817644 1.29076523 -0.34018681 1.76389569 0.08708504 -0.04899897
## [13] -0.06016687 0.70210235 -1.09241065 2.63601766 -0.84708286 0.02883056
## [19] -0.21764884 0.80429165
set.seed(42)
library(stats)
##
## Asymptotic two-sample Kolmogorov-Smirnov test
##
## data: norm and rnorm(n)
## D = 0.11, p-value = 0.5806
## alternative hypothesis: two-sided