TU Wien:Statistik und Wahrscheinlichkeitstheorie UE (Levajkovic)/Übungen 2023W/HW06.4

Aus VoWi
Zur Navigation springen Zur Suche springen
Normal distributions and neighborhoods

Let be a normal random variable with the expectation 5 and the variance 4. Let be a random sample from this distribution. Consider two statistics, the sample sum and the sample mean , given by and .

(a) What are the distributions of and of ?

(b) Use R-command plot to plot the density of and the density of .

(c) Which quantiles of the normal distribution mark the neighborhoods of the mean that contain 95%, and 99.9% of the probability density? Which values do they take? Add these neighborhoods to the plot. Add the corresponding neighborhoods to the plot of the density of the sample mean.

(d) Generate a sample of 50 random numbers from and plot the histogram for this sample.

Dieses Beispiel ist als solved markiert. Ist dies falsch oder ungenau? Aktualisiere den Lösungsstatus (Details: Vorlage:Beispiel)


Lösungsvorschlag von Lessi[Bearbeiten | Quelltext bearbeiten]

--Lessi 2024-02-07T13:04:11Z

# Let X be a random variable, then X ~ N(5, 4). Let X1, ..., X50 be a sample of 50 independent identical copies of X. 
# Then S = X1 + ... + X50 and X_bar = 1/50 * (X1 + ... + X50)

# a) 
# Based on CLT S is approx N(50 * 5, 50 * 4) and X_bar is approx N(5, 1/50 * 4)

# b) 


upper <- qnorm(0.999, 5, 2)
lower <- qnorm(0.001, 5, 2)
x <- seq(lower, upper, by=0.25)

X <- dnorm(x, 5, 2)
X_bar <- dnorm(x, 5, 2 / sqrt(50))

par(mfrow = c(2, 1))
plot(x, X, col="red", main="Density Functions", ylab="Density of base distribution")
lines(x, X, col="red")
plot(x, X_bar, col="blue", ylab="Density of sample means")
lines(x, X_bar, col="blue")

# c) 
# We want the IQR for 95% and 99.9%

x025 <- qnorm(0.025, 5, 2)
x975 <- qnorm(0.975, 5, 2)

x0005 <- qnorm(0.0005, 5, 2)
x9995 <- qnorm(0.9995, 5, 2)

x025_bar <- qnorm(0.025, 5, 2 / sqrt(50))
x975_bar <- qnorm(0.975, 5, 2 / sqrt(50))

x0005_bar <- qnorm(0.0005, 5, 2 / sqrt(50))
x9995_bar <- qnorm(0.9995, 5, 2 / sqrt(50))


par(mfrow = c(2, 1))
ylim <- range(0, dnorm(5, 5, 2) + 0.1)
plot(x, X, ylim=ylim, col="red", main="Density Functions", ylab="Density of base distribution")
lines(x, X, col="red")
arrows(x025, 0, x975, 0, col='green', code=3, angle=90, lwd=2)
arrows(x0005, 0, x9995, 0, col='orange', code=3, angle=90, lwd=2)
legend('topright','groups', c("X", "95% Neighborhood", "99.9% Neighborhood"), lty = c(1,1),
       col=c('red','green', 'orange'), ncol=3, cex=0.5)


ylim <- range(0, dnorm(5, 5, 2 / sqrt(50)) + 0.2)
plot(x, X_bar, ylim=ylim, col="blue", ylab="Density of sample means")
lines(x, X_bar, col="blue")
arrows(x025_bar, 0, x975_bar, 0, col='green', code=3, angle=90, lwd=2)
arrows(x0005_bar, 0, x9995_bar, 0, col='orange', code=3, angle=90, lwd=2)
legend('topright','groups', c(expression(bar(X)), "95% Neighborhood", "99.9% Neighborhood"), lty = c(1,1),
       col=c('blue','green', 'orange'), ncol=3, cex=0.5)


# d) 
par(mfrow = c(1, 1))
sample <- rnorm(50, 5, 2)
hist(sample, breaks = seq(min(sample) - 1, max(sample) + 1, by=0.25), prob=TRUE, main="Histogram of X", xlab="x")