Multivariate Statistik - Aufgabe 5 - Diskriminanz-/Hauptkomponentenanalyse
From StatWiki
Contents |
Beispiel 1
The function to calculate the apriori probability is
where
library(mvtnorm)
aposteriori = function(x,apriori) {
m=matrix(c(0,0,0,1,2,3,3,3,4),nrow=3)
s=matrix(c(1,0.5,0.5,0.5,1,0.5,0.5,0.5,1),nrow=3,byrow=T)
denum=0
for(i in 1:ncol(m)) {
denum=denum+dmvnorm(x,m[,i],s)*apriori[i]
}
ret = rep(0,ncol(m))
for(i in 1:ncol(m)) {
ret[i] = (dmvnorm(x,m[,i],s)*apriori[i]) / denum
}
ret
}
#
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
dmvnorm(...) returns
as found in en:Multivariate normal distribution
For the 3 observations
,
and
with aprioris
the aposterios are given by
library(mvtnorm) aposteriori(c(0,0,0),rep(1/3,3)) aposteriori(c(1,2,3),rep(1/3,3)) aposteriori(c(0.5,1,1.5),rep(1/3,3)) #
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Therefore
is assigned to group 1,
is assigned to group 2 and
is just between group 1 and 2.
For aprioris
and
. The aposterios are given by
library(mvtnorm) aposteriori(c(0,0,0),c(0.49,0.02,0.49)) aposteriori(c(1,2,3),c(0.49,0.02,0.49)) aposteriori(c(0.5,1,1.5),c(0.49,0.02,0.49)) #
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Therefore
and
are assigned to group 1 and
is assigned to group 3.
