LilBros13
LilBros13

Reputation: 11

Kolmogorov-smirnov test in a matrix

r code

B = 10
CC <- numeric(B)
for(j in 1:10)
  N = rnorm(1000)
  print(ks.test(N,pnorm)$statistic)
  CC[j] <- ks.test(N,pnorm)$statistic
  print(CC[j])
print(CC)

if you run this in r you will get a matrix with 9 zeros and only the last term is an actually numeric value. Can someone please explain why this is happening and how can i get the numerical values on the other indices.

Upvotes: 1

Views: 387

Answers (1)

Andrew Chisholm
Andrew Chisholm

Reputation: 6567

It could be because of missing {}. Try this:

B = 10
CC <- numeric(B)
for(j in 1:10) {
  N = rnorm(1000)
  print(ks.test(N,pnorm)$statistic)
  CC[j] <- ks.test(N,pnorm)$statistic
  print(CC[j])
}
print(CC)

Upvotes: 2

Related Questions