diff options
| Commit | a1ddf90dd755b7e862882bd7304ecccd228a1712 (patch) | |
|---|---|---|
| Author | 2024-04-16 12:52:51 +0300 | |
| Committer | 2024-04-16 12:52:51 +0300 | |
| Files | c204c572c61c68788fe70c6841550d2fa9f3d987 /Year 3/Statistics/hw1.r | |
| uni-projects-a1ddf90dd755b7e862882bd7304ecccd228a1712.tar uni-projects-a1ddf90dd755b7e862882bd7304ecccd228a1712.tar.gz uni-projects-a1ddf90dd755b7e862882bd7304ecccd228a1712.zip | ||
| Parent | c146d10ae0462a47d4caaec7bc86bd1f18280409 (diff) | |
[S/hw1] Solved homework
1 files changed, 38 insertions, 0 deletions
| -rw-r--r-- | Year 3/Statistics/hw1.r | 38 |
diff --git a/Year 3/Statistics/hw1.r b/Year 3/Statistics/hw1.r new file mode 100644 index 0000000..3112182 --- /dev/null +++ b/Year 3/Statistics/hw1.r @@ -0,0 +1,38 @@ +ex1 <- function(total = 24, marked = 4, boxes = 4, iterations = 10000) { + perbox <- total %/% boxes + successes <- 0 + + for (i in 1:iterations) { + apples <- sample(append(rep("marked", each=marked), rep("normal", each=total - marked))) + + current <- 0 + for (b in 1:boxes) { + current <- current + (sum(apples[1:perbox + (b-1)*perbox] == "marked") == 1) + } + + successes <- successes + (current == 4) + } + + return (successes / iterations) +} + +ex1() + +ex2 <- function(n, lambda = 1/5, N = 10000, mu = 5, sigma = 5 / sqrt(n)) { + xdash <- replicate(N, sum(rexp(n, rate=lambda)) / n) + + fchapeau <- function(t) { + return (1 / N * sum(xdash <= t)) + } + + t <- seq(0, 10, by=0.1) + Fpoints <- sapply(t, fchapeau) + Npoints <- sapply(t, function(t) { return (dnorm(t, mu, sigma)) }) + + plot(t, Fpoints, type="l", ylim=c(0, 1.1)) + lines(t, Npoints, lty=2) +} + +ex2(30) +ex2(120) +ex2(200)
\ No newline at end of file |
