Reputation: 11
Let be a set of X_1, ..., X_n - independent identically distributed random variables with cumulative distribution function F(x). Let denote the empirical distribution function as F_n(x).
Lets introduce the value Dn (the so-called statistics of the Kolmogorov-Smirnov criterion):
I need to prove with plots that
I tried this, but I don't understand why I get wrong plots (I need basic gtaphic functions or lattice)
`
if (!require("latex2exp")) install.packages("latex2exp")
library("latex2exp")
# 1. Dn has a limit distribution for n -> inf
DNorm <- function(x, mean = 0, sd = 1) {
emp.cdf <- ecdf(x)
n = length(x)
df <- data.frame(emp.cdf = emp.cdf(x), pnorm = pnorm(x, mean, sd))
vec <- (abs((df$emp.cdf - df$pnorm)))
res <- max(vec)* sqrt(n)
}
DnNorm <- function(n, mean = 0, sd = 1) {
x <- sapply(10:n, rnorm, mean, sd)
res <- sapply(x, RNorm, mean, sd)
}
pdf(file="1.pdf")
par(mfrow=c(2,2))
hist(DnNorm(100), breaks = 10, xlim = c(0, 3), col = "cyan1", main = "n = 100", xlab = "Dn")
hist(DnNorm(1000), breaks = 15, xlim = c(0, 3), col = "cyan1", main = "n = 1000", xlab = "Dn")
hist(DnNorm(5000), breaks = 15, xlim = c(0, 3), col = "cyan1", main = "n = 5000", xlab = "Dn")
dev.off()
# 2. Asymptotic distribution of Dn is independent of the distribution function F(x).
pdf(file="2.pdf")
par(mfrow=c(3,1))
hist(DnNorm(3000), breaks = 15, xlim = c(0, 3), col = "cyan1", main = "N(0, 1)", xlab = "Dn")
hist(DnNorm(3000, 50, 4), breaks = 15, xlim = c(0, 3), col = "cyan1", main = "N(50, 4)", xlab = "Dn")
hist(DnNorm(3000, 1), breaks = 15, xlim = c(0, 3), col = "cyan1", main = "EXP(1)", xlab = "Dn")
dev.off()
`
Upvotes: 0
Views: 81
Reputation: 1
@Yana Sal Maybe you need to correct the line in function DnNorm
with:
{res <- sapply(x, DNorm, mean, sd)} # replace RNorm with your function DNorm()`
Upvotes: 0