--------------- # Aufgabe 2 # --------------- # 2a) n = 1000 x = rexp(n,rate=4) plot(x) hist(x,breaks=50) # 2b) lambda_ml = 1/(sum(x)/n) lambda_mod = 1/(sum(x)/(n-1)) lambda_ml lambda_mod # 2c) lambda = seq(from=0.1, to=10, by=0.1) nlambda = length(lambda) nlambda # 100, ok logL = rep(0,nlambda) jlam = 1 for(lam in lambda) { logL[jlam] = sum( log(dexp(x,rate=lam)) ) jlam = jlam + 1 } plot(lambda,logL) max(logL) k = which.max(logL) # index for the maximum logL[k] # identical to max(logL), ok lambda[k] # is closest value to lambda_ml, ok # 2d) n = 10000 x = rexp(n,rate=4) plot(x) hist(x,breaks=50) lambda_ml = 1/(sum(x)/n) lambda_mod = 1/(sum(x)/(n-1)) lambda_ml lambda_mod # let's increase the resolution: lambda = seq(from=0.1, to=10, by=0.001) nlambda = length(lambda) nlambda # now 9901 logL = rep(0,nlambda) jlam = 1 for(lam in lambda) { logL[jlam] = sum( log(dexp(x,rate=lam)) ) jlam = jlam + 1 } plot(lambda,logL) max(logL) k = which.max(logL) # index for the maximum logL[k] # identical to max(logL), ok lambda[k] # is closest value to lambda_ml, ok