TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2022W/HW05.5

Aus VoWi
Zur Navigation springen Zur Suche springen
Histograms of averages of exp(1)
(a) Generate a frequency histogram of 1000 samples from an exp(1) random variables.
(b) Generate a density histogram for the average of 2 independent exp(1) random variable.
(c) Using rexp(), matrix() and colMeans() generate a density histogram for the average of 50 independent exp(1) random variables. Make 10000 sample averages and use a binwidth of 0.1 for this. Look at the spread of the histogram.
(d) Add a graph of the pdf of on your plot in problem (c).
Dieses Beispiel hat einen unbekannten Lösungsstatus. Bitte editiere diese Seite und schreibe den dir bekannten Status ins Beispiel. Die möglichen Werte sind hier: Vorlage:Beispiel dokumentiert. Führe folgende Änderung durch:
{{Beispiel|1=
Angabetext
}}

oder

{{Beispiel|
Angabetext
}}

zu (im Falle einer korrekten, unverifizierten Lösung "solved". Auch möglich "unsolved", "wrong", "verified_by_tutor". Alle möglichen Werte sind hier: Vorlage:Beispiel dokumentiert.)

{{Beispiel|status=solved|1=
Angabetext
}}


Lösungsvorschlag von Friday[Bearbeiten | Quelltext bearbeiten]

--Friday Sa 30 Jan 2021 17:03:56 CET

# Statistics and Probability HW #5
# Friday 
# Duedate: 09.11.2020

# Problem 6 - Histograms of averages of exp(1)

# Problem 6a)
# Generate a frequency histogram of 1000 samples from an exp(1) random 
# variables.
d = rexp(1000,1)
hist(d, freq=TRUE, xlab="", ylab="frequency", main="Frequency Histogram")

# Problem 6b)
# Generate a density histogram for the average of 2 independent exp(1) random 
# variable.
d1 = rexp(1000,1)
d2 = rexp(1000,1)
d = (d1 + d2) / 2
hist(d, freq = TRUE, xlab="", ylab="density", main="Desity Histogram")

# Problem 6c)
# Using rexp(), matrix() and colMeans() generate a density histogram for the 
# average of 50 independent exp(1) random variables. Make 10000 sample averages 
# and use a binwidth of 0.1 for this. Look at the spread of the histogram.
exp = 50
n = 10000
x = rexp(n*exp,1)
tmp = matrix(x, nrow=exp, ncol=n)
d = colMeans(tmp)
hist(d, freq=FALSE, xlab="", ylab="density", main="Desity Histogram")

# Problem 6d)
# Add a graph of the pdf of N(1, 1/50) on your plot in problem (c).
d = seq(0,2,.01)
lines(d,dnorm(d,1,1/sqrt(50)),lwd=3)

Lösungsvoschlag von Simplex[Bearbeiten | Quelltext bearbeiten]

# a)
samples = rexp(1000, 1)
hist(samples)

# b)
var1 <- rexp(1000, 1)
var2 <- rexp(1000, 1)
avg <- (var1 + var2)/2
hist(avg, freq=FALSE)

# c)
mat <- matrix(nrow=50, ncol=10000)
for (i in 1:50)
  mat[i,] <- rexp(10000, 1)
avg <- colMeans(mat)

bin_width <- 0.1
bins <- seq(min(avg), max(avg) + bin_width, bin_width)
hist(avg, breaks=bins, freq=FALSE)

# d)
sd <- 1/50
x <- seq(1 - 3*sqrt(sd), 1 + 3*sqrt(sd), 0.001)
norm_values <- dnorm(x, 1, sqrt(sd))
lines(x, norm_values)

--Simplex 15:25, 3. Feb. 2023 (CET)