Skip to content

Commit

Permalink
Add URM stat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaakshat committed Oct 21, 2021
1 parent 73aff20 commit 8afad09
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ch04.r
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,39 @@ plot(x, f, type="n")
lines(x, f, lwd=5)
plot(x, F, type="n")
lines(x, F, lwd=5)

# Chapter 4.5

# Generate a uniform random variable

# R code to generate 1000 uniform random numbers
a = 0; b = 1;
X = runif(1000, a, b)
hist(X)

# Mean, variance, median, mode of a uniform random variable

# R code to computer empirical mean, var, median, mode
library(pracma)
a = 0; b = 1;
X = runif(1000, a, b)
M = mean(X)
V = var(X)
Med = median(X)
Mod = Mode(X)

# R code to compute mean and variance
unifstat = function(a, b) {
M = (a+b)/2
V = ((a-b)^2)/12
return(list(mean = M, var = V))
}

a = 0; b = 1;
M = unifstat(a, b)$mean
V = unifstat(a, b)$var

# R code to compute the probability P(0.2 < X < 0.3)
a = 0; b = 1;
F = punif(0.3, a, b) - punif(0.2, a, b)

0 comments on commit 8afad09

Please sign in to comment.