#---------------------------# # Loesungen UeBlatt13 # #---------------------------# --------------- # Aufgabe 1 # --------------- bevdata = read.table("C:/Users/detlef/OneDrive/hochschule/Vorlesungen/WS2122/Oekonometrie/Weltbevoelkerung.csv",header=TRUE,sep=";") bevdata bev = bevdata[,4] bev zeiten = bevdata[,3] zeiten plot(zeiten,bev) zeiten[14] zeiten2 = zeiten[1:14] bev2 = bev[1:14] zeiten2 = zeiten2 -1950 zeiten = zeiten -1950 logbev2 = log(bev2) # Geben wir zunaechst noch einmal die # Regressionskoeffizienten an: # Modell (1): res1 = lm(bev2 ~ zeiten2) a0 = res1\$coef[1] a1 = res1\$coef[2] a0 a1 # Modell (2): X = cbind(zeiten2,zeiten2^2) res2 = lm(bev2 ~ X ) b0 = res2\$coef[1] b1 = res2\$coef[2] b2 = res2\$coef[3] b0 b1 b2 # Modell (3): res3 = lm(logbev2 ~ zeiten2) beta0 = res3\$coef[1] beta1 = res3\$coef[2] B0 = exp(beta0) r = beta1 B0 r # Die Vertrauensintervalle sind gegeben durch # # hat_beta plus/minus stddev * q_alpha # # wobei die Standardabweichung stddev aus den Re- # gressionsresultaten abgelesen werden kann und # bei Vertauenslevel alpha=90% # # q90 = qt(0.95,df=n-p) # # wenn n der Stichprobenumfang und p die Anzahl # der Regressoren ist (mit intercept oder konstantem # Term). n = 14 # Modell (1): summary(res1) # also: stddev_a0 = 58278 stddev_a1 = 1524 p = 2 q90 = qt(0.95,df=n-p) # damit: a0up = a0 + stddev_a0*q90 a0down = a0 - stddev_a0*q90 a1up = a1 + stddev_a1*q90 a1down = a1 - stddev_a1*q90 confint_a0 = c(a0down,a0up) confint_a1 = c(a1down,a1up) confint_a0 confint_a1 # Modell (2): summary(res2) # also: stddev_b0 = 3.910*10^4 stddev_b1 = 2.793*10^3 stddev_b2 = 4.143*10^1 p = 3 q90 = qt(0.95,df=n-p) # damit: b0up = b0 + stddev_b0*q90 b0down = b0 - stddev_b0*q90 b1up = b1 + stddev_b1*q90 b1down = b1 - stddev_b1*q90 b2up = b2 + stddev_b2*q90 b2down = b2 - stddev_b2*q90 confint_b0 = c(b0down,b0up) confint_b1 = c(b1down,b1up) confint_b2 = c(b2down,b2up) confint_b0 confint_b1 confint_b2 # Modell (3): summary(res3) # also: stddev_beta0 = 0.0156 stddev_beta1 = 0.0004079 p = 2 q90 = qt(0.95,df=n-p) q90 # damit: beta0up = beta0 + stddev_beta0*q90 beta0down = beta0 - stddev_beta0*q90 beta1up = beta1 + stddev_beta1*q90 beta1down = beta1 - stddev_beta1*q90 confint_B0 = c(exp(beta0down),exp(beta0up)) confint_r = c(beta1down,beta1up) confint_B0 confint_r --------------- # Aufgabe 2 # --------------- # 2a) store the Excel-data as csv-file and make sure that numbers in Excel are # formatted properly (ohne Hochkomma oder aehnliches..) bip = read.table("C:/Users/detlef/OneDrive/hochschule/Vorlesungen/WS2122/Oekonometrie/BIP-Deutschland.csv",header=FALSE,sep=";") bip y = bip[,2] y x = bip[,1] x x = x - 1991 x plot(x,y) # 2b) res = lm(y ~ x) betas = res\$coeff beta0hat = betas[1] beta1hat = betas[2] beta0hat # = B_{t_0} beta1hat # = r plot(x,y) lines(x,res\$fit,col=2) # 2c) Vertrauensintervalle: # # beta0hat +/- q_alpha stddev_beta0 # beta1hat +/- q_alpha stddev_beta1 n = length(x) n p = 2 q90 = qt(95/100,df=n-p) q90 q95 = qt(97.5/100,df=n-p) q95 q99 = qt(99.5/100,df=n-p) q99 summary(res) # also: stddev_beta1 = 1.346 beta1up90 = beta1hat + q90*stddev_beta1 beta1up95 = beta1hat + q95*stddev_beta1 beta1up99 = beta1hat + q99*stddev_beta1 beta1down90 = beta1hat - q90*stddev_beta1 beta1down95 = beta1hat - q95*stddev_beta1 beta1down99 = beta1hat - q99*stddev_beta1 confint1_90 = c(beta1down90,beta1up90) confint1_95 = c(beta1down95,beta1up95) confint1_99 = c(beta1down99,beta1up99) confint1_90 confint1_95 confint1_99