amv29 - Tests on a Mean Vector with Known Covariance Matrix

preview_player
Показать описание
Help this channel to remain great! Donating to Patreon or Paypal can do this!
Рекомендации по теме
Комментарии
Автор

The following line of code does not appear to get used in the script and causes and error m<-vec[2, 2]/vec[1, 2] ??

BenBenford-xi
Автор

begin video 1

x<-c(69, 74, 68, 70, 72, 67, 66, 70, 76, 68, 72, 79, 74, 67, 66, 71, 74, 75, 75, 76)
y<-c(153, 175, 155, 135, 172, 150, 115, 137, 200, 130, 140, 265, 185, 112, 140, 150, 165, 185, 210, 220)
mu<-c(70, 170)
Sig<-matrix(c(20, 100, 100, 1000), ncol=2)
mahalanobis(c(mean(x), mean(y)), mu, Sig/length(x))
qchisq(.95, 2)

## Simple function to draw ellipes
draw.ellipse <- function(mu, cov.mat, c2, jmp=.1) {
vec<- eigen(cov.mat)$vectors
val<- eigen(cov.mat)$values
len.x <- sqrt(c2*val[1])
len.y <- sqrt(c2*val[2])
angle <- atan(vec[2, 1]/vec[1, 1])
rotate <- matrix(c(cos(angle), sin(angle), -sin(angle), cos(angle)), ncol=2)
x.ellip <- seq(-len.x, len.x, jmp)
y1 <- sqrt(len.y^2 - (len.y*x.ellip/len.x)^2)
y2 <- -y1
angle <- atan(vec[2, 1]/vec[1, 1])
rotate <- matrix(c(cos(angle), sin(angle), -sin(angle), cos(angle)), ncol=2)
ellip1 <- rotate %*% rbind(x.ellip, y1)
ellip2 <- rotate %*% rbind(x.ellip, y2)
list("x"=ellip1[1, ]+mu[1], "x.e"=ellip1[2, ]+mu[2], "y"=ellip2[1, ]+mu[1], "y.e"=ellip2[2, ]+mu[2])
}

x<-c(69, 74, 68, 70, 72, 67, 66, 70, 76, 68, 72, 79, 74, 67, 66, 71, 74, 75, 75, 76)
y<-c(153, 175, 155, 135, 172, 150, 115, 137, 200, 130, 140, 265, 185, 112, 140, 150, 165, 185, 210, 220)
mu<-c(70, 170)
Sig<-matrix(c(20, 100, 100, 1000), ncol=2)/length(x)
m<-vec[2, 2]/vec[1, 2]
alpha <- 0.05
plot(x, y, ylab="Weight (lbs)", xlab="Height (inches)", main="20 College-age Males")
points(mu[1], mu[2], pch=18, col='red', cex=2)
points(mean(x), mean(y), pch=18, col='blue', cex=1)
elli <- draw.ellipse(mu, Sig, qchisq(1-alpha, 2), .001)
lines(elli$x, elli$x.e, col='red')
lines(elli$y, elli$y.e, col='red')
legend("topleft", c("95% Conf Ellipse", "95% Univariate CI's", "Null Hypothesis", "Sample Mean"),
lty=c(1, 1, NA, NA), pch=c(NA, NA, 18, 18), col=c('red', 'black', 'red', 'blue'))
x1<-mu[1]+qnorm(alpha/2)*sqrt(Sig[1, 1])
x2<-mu[1]+qnorm(1-alpha/2)*sqrt(Sig[1, 1])
y1<-mu[2]+qnorm(alpha/2)*sqrt(Sig[2, 2])
y2<-mu[2]+qnorm(1-alpha/2)*sqrt(Sig[2, 2])
polygon(c(x1, x2, x2, x1), c(y1, y1, y2, y2))

plot(x, y, ylab="Weight (lbs)", xlab="Height (inches)", main="20 College-age Males",
xlim=c(67, 73), ylim=c(150, 190), type = 'n')
mtext("Zoomed In")
points(mu[1], mu[2], pch=18, col='red', cex=2)
points(mean(x), mean(y), pch=18, col='blue', cex=1)
lines(elli$x, elli$x.e, col='red')
lines(elli$y, elli$y.e, col='red')
polygon(c(x1, x2, x2, x1), c(y1, y1, y2, y2))

end video 1

statisticsmatt
join shbcf.ru