My super prof. teach me this stuff. Many Thank for Prof. Dr. Beate Bergter HTW Berlin
Ü1. Statistische Grundbegriffe
###########################Sonderblatt R###########################Machen Sie sich mit grundlegenden Funktionen in R vertraut, #indem Sie die folgenden Befehle nacheinander ausführen.x <-c(3,4,3,5,6,3,5,6,7,8)y <-c(1,1,1,1,1,2,2,2,2,2)z <-c(5,2,3,6,1,3,4,5,4,1)xyzlength(x)sum(x)cumsum(y)plot(x,z)x[7]x[y==2]m <-matrix(c(x,y,z), nrow=10)m2 <-matrix(c(x,y,z), nrow=10, byrow=TRUE)m3 <-cbind(x,y,z)d <-data.frame(x,y,z)mdstr(m)str(d)t(m) #transposem[7,2]m[2,7]t(m)[2,7]m[2,]d[y==2,]summary(d)plot(d)#Hilfestellung in R###############################?mean apropos(mean) #what?help.start()
#Aufgabe 5
# Eingabe der Daten: x = Alter, y = Verkaufswert
x<-c(0,1,3,5,6)
y<-c(65,45,40,30,20)
Auto<-data.frame(Alter=x,Verkaufswert=y)
plot(Auto,lwd=8,main="Zusammenhang zwischen Alter und Verkaufswert",col="red", ylim=c(0,70))
cor(x, y, method="spearman")
cor(x, y, method="pearson")
# oder einfacher:
cor(x, y)
# oder direkt mit
cor(Auto, method="spearman")
cor(Auto)
help(lm) # R Hilfe zur linearen Regression
fm<-lm( Verkaufswert ~Alter , data = Auto)
coef(fm) # Koeffizienten der Ausgleichsgeraden
# Graphische Darstellung: Scatterplot und Ausgleichsgerade
plot(Auto,lwd=8,main="Zusammenhang zwischen Alter und Verkaufswert",col="red", ylim=c(0,70))
abline(fm,lwd=2, col="blue")
#################
#Aufgabe 1
####################
t<-seq(from=1,to=8,by=1)
y<-c(49,47,56,58,59,53,57,54)
# als time series
d.y <- ts(y, start=c(2005,1),frequency=1)
#filter
y_f2 <- filter(d.y, filter=c(1,1,1)/3)
y_f1 <- filter(d.y, filter=c(0.5,1,1,1,0.5)/4)
par(mfrow = c(2,1) )
plot(d.y, type = "b", main = "Zeitreihe", lwd = 2,col=2)
plot(y_f2, type = "b", main = "3 -glatt", lwd = 2,col=2)
plot(d.y, type = "b", main = "Zeitreihe", lwd = 2,col=2)
plot(y_f1, type = "b", main = "4-glatt", lwd = 2,col=2)
#oder
y1<-(1/3)*(d.y + lag(d.y,-1)+ lag(d.y,+1)) #zentriert
#y2<-0.25*(d.y + lag(d.y,-1)+ lag(d.y,-2)+ lag(d.y,-3))
y2<-0.25*(d.y + lag(d.y,-1)+ 0.5*lag(d.y,-2)+ lag(d.y,+1)+ 0.5* lag(d.y,+2)) #zentriert
par(mfrow = c(1,1) )
plot(d.y, ylab="ZR", xlab="Zeit",main="ZR und Glättung", type = "b",col="blue",
frame.plot = TRUE, xaxs = "i", pch=4)
lines(y1, col = 2, lwd = 2, type = "b")
lines(y2, col = 3, lwd = 2, type = "b")
t<-seq(from=1,to=13,by=1)
U<-c(11300,10631,9949,9814,9454,8758,8549,7792,7772,7503,6977,6842,6606)
# als time series
t.U <- ts(U, start=c(1991,1),frequency=1)
plot(t.U)
#a)
#Geometrisches Mittel
(6606/11300)^(1/length(U)) # 0.96 -> jährlich 4 Prozent weniger
#Prognose für 2004
6606*(6606/11300)^(1/length(U)) #6339
#Prognose für 2005
6606*(6606/11300)^(2/length(U)) #6083
#b) Trendmodell linearisieren
#ln U = ln b0+ lnb1 *t
u<-log(U)
Trend<- lm(log(U) ~ t); a0 <- Trend$coeff[1]; a1<- Trend$coeff[2]
coef(Trend)
summary(Trend)
#en detail
sum((t-mean(t))^2)
sum((u-mean(u))^2)
sum((t-mean(t))*(u-mean(u)))
beta<-sum((t-mean(t))*(u-mean(u)))/sum((t-mean(t))^2)
alpha<-mean(u)-beta*mean(t)
b0<-exp(a0)
b1<-exp(a1) # 0.956
#Prognose für 2004: U(14)
b0*b1^(14) #6203
#Prognose für 2005: U(15)
b0*b1^(14) #5931