################ ### EXERCISE 3.1 NORMAL DISTRIBUTION ################ ### A) ### Let the weight distribution of a production series ### of a tinned product be normally distributed with ### expectation mu and standard deviation sigma. ### Plot the distribution function for different mu and ### variance sigma^2. Use additional graphic parameters ### you know from Exercises_part2, e.g. xlab, cex.lab, etc. mu = 800 sigma2 = 100 x = seq(800-200, 800+200, 1) y = dnorm(x, mean=mu, sd=sqrt(sigma2)) plot(x, y, type="l") ### B) ### Given mu=800g and sigma2=100, determine the probability ### that a weight of an individual piece of the production ### is less or equal tau=790g. You can use the cumulative distribution ### function of the normal distribution. tau = 790 res = pnorm(tau, mean=800, sd=10) res x = seq(800-30, 800+30, 1) y = pnorm(x, mean=mu, sd=10) plot(x, y, type="l") lines(c(tau, tau), c(0, res), type="l", lty=2) lines(c(0, tau), c(res, res), type="l", lty=2) ### What is the probability that a selected piece has a weight ### of more than tau? ### C) ### Draw a random sample from your production using different ### sample sizes n. Determine mean, sd and quartiles (25%, 50%, 75%-quantiles) ### of your sample. ### Compare estimates from the sample and true values of the distribution. mu = 800 sigma = 10 n = 10 S = rnorm(n=n, mean=mu, sd=sigma) S ### Estimates from the sample: summary(S) var(S) sd(S) ### True quantiles qnorm(p=c(.25, .5, .75), mean=mu, sd=sigma) ################ ### EXERCISE 3.2 BINOMIAL DISTRIBUTION ################ ### A) ### Consider you sample n pieces from your production. ### Further, assume the production process is configured ### such that the probability that a particular piece is ### useable is p (useable means the piece can be sold). ### Draw the probability function for different n and p. n = 100 p = 0.8 x = seq(0, 100, 1) y = dbinom(x, size=n, prob=p) plot(x, y, type="h", xlab="Number of useable pieces", ylab="Probability") ### B) ### Given n=100 and p=0.8. ### Determine the probability that exactly 90 pieces of your ### production can be used. dbinom(90, size=100, prob=0.8) plot(x, y, type="h", xlab="Number of useable pieces", ylab="Probability") points(c(90, 90), c(0, dbinom(90, size=100, prob=0.8)), col=2, type="l", lwd=2) ### Determine the probability that less than 90 pieces are usable. ### Use the cumulative distribution function. pbinom(89, size=100, prob=0.8) res = pbinom(89, size=100, prob=0.8) x = seq(0, 100, 1) y = pbinom(x, size=n, prob=p) plot(x, y, xlab="Number of useable pieces", ylab="Cumulative Probability") lines(c(89, 89), c(0, res), type="l", lty=2) lines(c(0, 89), c(res, res), type="l", lty=2) ### Attention: the cumulative distribution function ### of a discrete variable is usually a step function. ### C) ### Simulate the following scenario: ### Consider you draw each day of the year a random sample of n=100 pieces ### of your production as a quality control, and study the number of useable pieces. ### Your production is anticipated to have a rate of 97% of useable pieces. ### Determine mean and quartiles (25%, 50%, 75%-quantiles) of your sample. ### Compare estimates from the sample and true values of the distribution. n = 100 p = 0.97 S = rbinom(365, size=n, prob=p) S ### Estimates from the samples. ### Remark: estimates need to be devided by n to obtain probabilities ### in the range of [0, 1]. summary(S)/n ### True quantiles. qbinom(p=c(.25, .5, .75), size=n, prob=p)/n ### Since quality control is expensive, try out whether smaller n yield sufficient ### estimates. ################ ### EXERCISE 3.3 ################ ### Draw density function and cumulative distribution functions ### for the Poisson distribution and the Exponential distribution. ### Follow Examples 9 and 10 from the lecture. ### You can use the function dpois, dexp, etc. ### Use the functions rpoins and rexp to draw random data from the ### both distributions.