diff options
1 files changed, 5 insertions, 5 deletions
| -rw-r--r-- | Year 3/Statistics/hw1.r | 10 |
diff --git a/Year 3/Statistics/hw1.r b/Year 3/Statistics/hw1.r index ec9f021..afb1be3 100644 --- a/Year 3/Statistics/hw1.r +++ b/Year 3/Statistics/hw1.r @@ -19,7 +19,7 @@ ex1 <- function(total = 24, marked = 4, boxes = 4, iterations = 10000) { ex1() ex2 <- function(n, lambda = 1/5, N = 10000, mu = 5, sigma = 5 / sqrt(n)) { - x <- function() rexp(n, rate=lambda) + x <- function() rexp(n, rate=lambda) xdash <- replicate(N, sum(x()) / n) fchapeau <- function(t) { @@ -28,12 +28,12 @@ ex2 <- function(n, lambda = 1/5, N = 10000, mu = 5, sigma = 5 / sqrt(n)) { return (1/N * sum(I(xdash <= t))) } - t <- seq(0, 10, by=0.1) + t <- seq(2, 8, by=0.1) Fpoints <- sapply(t, fchapeau) - Npoints <- sapply(t, function(t) dnorm(t, mu, sigma)) + Npoints <- sapply(t, function(t) pnorm(t, mu, sigma)) - plot (t, Fpoints, type="l", ylim=c(0, 1.1)) - lines(t, Npoints, lty=2) + plot (t, Fpoints, type="l") + lines(t, Npoints, lty=2, col="darkred") } ex2(30) |
