Docsity

Multivariable Data Analysis - Lecture Notes | STA 135, Exams of Descriptive statistics

Toggle sidebar
bg1
1-Way MANOVA via Regression, example1: p=3, g=2
################One-Way MANOVA########
X=read.table("Sta135jiming/Wichern_data/T6-9.dat")
names(X)=c("L","W","H","Gender")
> X
L W H Gender
1 98 81 38 female
2 103 84 38 female
3 103 86 42 female
:
25 93 74 37 male
26 94 78 35 male
:
X[,1:3]=log(X[,1:3]) #authors suggest to transform the data
###use stacked observations (do not separate into diffe rent datasets)
Y=as.matrix(X[,1:3])
###No. of observations, No. of variables
n=nrow(Y)
p=ncol(Y)
n1=table(X$Gender)[1]
n2=table(X$Gender)[2]
####Design matrix####
####Code variables in the FULL model:
####column1: all 1(for intercept term),
####column2: 1=female, -1=male
Z=matrix(0,ncol=2,nrow=n)
Z[,1]=rep(1,n)
Z[X$Gender=='female',2]=rep(1,n1)
Z[X$Gender=='male',2]=rep(-1,n2)
> Z
[,1] [,2]
[1,] 1 1
[2,] 1 1
[3,] 1 1
:
[25,] 1 -1
[26,] 1 -1
[27,] 1 -1
:
#####Columns of Z in full model#######
i_F=c(1,2)
g=length(i_F)
#####Columns of Z in reduced model#######
i_R=1
g1=length(i_R)
##### ANOVA table ############## ANOVA Test statist ic: reject Ho if
# SS df # F= SStr/(g-1) > F(g-1, Σ1
g{nl}–g)
# SStr g-1 # SSres/(Σ1
g{nl}–g)
# SSE(SSres) Σ1
g{nl} – g #
# SSto(SScor) Σ1
g{nl} – 1 #
################################
# In Regression formulation, use general linear test,
# SStr = SSEreduced – SSEfull
# SSres= SSEfull
##### MANOVA table ############# MANOVA Test statistic:
# Matrix SS df # Λ= |W|
# B g-1 # |B+W|
# W Σ1
g{nl} – g # reject H o based on cri teria
# B+W Σ1
g{nl} – 1 # of Table 3 (p.303)
################################
pf3
pf4

Partial preview of the text

Download Multivariable Data Analysis - Lecture Notes | STA 135 and more Exams Descriptive statistics in PDF only on Docsity!

1 - Way MANOVA via Regression, example1: p=3, g=

################One-Way MANOVA######## X=read.table("Sta135jiming/Wichern_data/T6-9.dat") names(X)=c("L","W","H","Gender") > X L W H Gender 1 98 81 38 female 2 103 84 38 female 3 103 86 42 female : 25 93 74 37 male 26 94 78 35 male : X[,1:3]=log(X[,1:3]) #authors suggest to transform the data ###use stacked observations (do not separate into different datasets) Y=as.matrix(X[,1:3]) ###No. of observations, No. of variables n=nrow(Y) p=ncol(Y) n1=table(X$Gender)[1] n2=table(X$Gender)[2] ####Design matrix#### ####Code variables in the FULL model: ####column1: all 1(for intercept term), ####column2: 1=female, - 1=male Z=matrix(0,ncol=2,nrow=n) Z[,1]=rep(1,n) Z[X$Gender=='female',2]=rep(1,n1) Z[X$Gender=='male',2]=rep(-1,n2) > Z [,1] [,2] [1,] 1 1 [2,] 1 1 [3,] 1 1 : [25,] 1 - 1 [26,] 1 - 1 [27,] 1 - 1 : #####Columns of Z in full model####### i_F=c(1,2) g=length(i_F) #####Columns of Z in reduced model####### i_R= g1=length(i_R)

ANOVA table ############## ANOVA Test statistic: reject Ho if

SS df # F= SStr/(g-1) > F(g-1, Σ 1 g{nl}–g)

SStr g- 1 # SSres/(Σ 1 g{nl}–g)

SSE(SSres) Σ 1 g{nl} – g

SSto(SScor) Σ 1 g{nl} – 1

################################

In Regression formulation, use general linear test,

SStr = SSEreduced – SSEfull

SSres= SSEfull

MANOVA table ############# MANOVA Test statistic:

Matrix SS df # Λ= |W|

B g- 1 # |B+W|

W Σ 1 g{nl} – g # reject Ho based on criteria

B+W Σ 1 g{nl} – 1 # of Table 3 (p.303)

################################

###Regression Estimator---Full model####

!ˆ^ =(Z'Z)-^1 Z'Y #- Beta Parameter estimates

##W=(Y-Z !ˆ^ )'(Y-Z !ˆ^ ) #- Error sum of squares and cross products matrix ##Yhat=Z !ˆ^ #- Predicted values ##E=Y-Yhat #- Residuals ###Full model Treatment sum of squares Bhat=solve(t(Z[,i_F]) %% Z[,i_F]) %% t(Z[,i_F]) %% Y ###Full model Error sum of squares and cross products matrix W=t(Y - Z[,i_F] %% Bhat) %% (Y - Z[,i_F] %% Bhat) ###Error covariance estimate S=W/(n-g) ########Reduced model estimate##### Bhat1=solve(t(Z[,i_R]) %%Z [,i_R]) %% t(Z[,i_R]) %% Y ###Reduced model error sum of products and cross products matrix G=t(Y - Z[,i_R] %% Bhat1) %% (Y - Z[,i_R] %% Bhat1) #####Hypothesis error sum of products B=G-W Lambda=det(W)/(det(B+W)) > Lambda [1] 0. ######### p=3,g=2, use Item 3 in Table 6.3; also, n= (1-Lambda)/Lambda*((n-p-1)/p) [1] 27. ####(27.11803 > F_{0.01, 3, 44}=4.26) qf(0.99,p,n-p-1)

1 - Way MANOVA via Regression, example p=2, g=

################# Example 6.9 ################## XX=data.frame(x1=c(9,6,9,0,2,3,1,2), x2=c(3,2,7,4,0,8,9,7), factor=as.factor(c(1,1,1,2,2,3,3,3)) ) > XX x1 x2 factor 1 9 3 1 2 6 2 1 3 9 7 1 4 0 4 2 5 2 0 2 6 3 8 3 7 1 9 3 8 2 7 3 ###use stacked observations (do not separate into different datasets) YY=as.matrix(XX[,1:2]) ###No. of observations, No. of variables n=nrow(YY) p=ncol(YY) n1=table(XX$factor)[1] n2=table(XX$factor)[2] n3=table(XX$factor)[3]

#####Columns of Z in full model####### i_F=c(1,2,3) g=length(i_F) #####Columns of Z in reduced model####### i_R= g1=length(i_R) ###Full model Treatment sum of squares Bhat=solve(t(Z[,i_F]) %% Z[,i_F]) %% t(Z[,i_F]) %% YY ###Full model Error sum of squares and cross products matrix W=t(YY - Z[,i_F] %% Bhat) %% (YY - Z[,i_F] %% Bhat) ###Error covariance estimate S=W/(n-g) ########Reduced model estimate##### BhatR=solve(t(Z[,i_R]) %%Z [,i_R]) %% t(Z[,i_R]) %% YY ###Reduced model error sum of products and cross products matrix G=t(YY - Z[,i_R] %% BhatR) %% (YY - Z[,i_R] %% BhatR) #####Hypothesis error sum of products B=G-W Lambda=det(W)/(det(B+W)) > Lambda [1] 0.

p=2, g=3, use Item 2 in Table 6.3; also, n=

(1-sqrt(Lambda))/sqrt(Lambda)((n-g-1)/(g-1)) [1] 8. ####(8.19886 > F_{0.01, 4, 8}=7.01) qf(0.99,2(g-1),2*(n-g-1))