ANOVA, ANCOVA and MANOVA as sem

Similar documents
Multivariate Analysis of Variance

MANOVA is an extension of the univariate ANOVA as it involves more than one Dependent Variable (DV). The following are assumptions for using MANOVA:

Multivariate analysis of variance and covariance

Principal component analysis

Extensions of One-Way ANOVA.

MODELS WITHOUT AN INTERCEPT

Multilevel Models in Matrix Form. Lecture 7 July 27, 2011 Advanced Multivariate Statistical Methods ICPSR Summer Session #2

Simple, Marginal, and Interaction Effects in General Linear Models

Extensions of One-Way ANOVA.

Neuendorf MANOVA /MANCOVA. Model: X1 (Factor A) X2 (Factor B) X1 x X2 (Interaction) Y4. Like ANOVA/ANCOVA:

Stat 412/512 TWO WAY ANOVA. Charlotte Wickham. stat512.cwick.co.nz. Feb

Nature vs. nurture? Lecture 18 - Regression: Inference, Outliers, and Intervals. Regression Output. Conditions for inference.

Lab 3 A Quick Introduction to Multiple Linear Regression Psychology The Multiple Linear Regression Model

Applied Multivariate Statistical Modeling Prof. J. Maiti Department of Industrial Engineering and Management Indian Institute of Technology, Kharagpur

Other hypotheses of interest (cont d)

Neuendorf MANOVA /MANCOVA. Model: MAIN EFFECTS: X1 (Factor A) X2 (Factor B) INTERACTIONS : X1 x X2 (A x B Interaction) Y4. Like ANOVA/ANCOVA:

Classification. Chapter Introduction. 6.2 The Bayes classifier

A Re-Introduction to General Linear Models (GLM)

MANOVA MANOVA,$/,,# ANOVA ##$%'*!# 1. $!;' *$,$!;' (''

Review of Multiple Regression

Experimental Design and Data Analysis for Biologists

Investigating Models with Two or Three Categories

Stat 5102 Final Exam May 14, 2015

CAS MA575 Linear Models

Neuendorf MANOVA /MANCOVA. Model: X1 (Factor A) X2 (Factor B) X1 x X2 (Interaction) Y4. Like ANOVA/ANCOVA:

Stat 401B Final Exam Fall 2016

MATH 644: Regression Analysis Methods

R Demonstration ANCOVA

Generalized linear models

An Introduction to Path Analysis

Introduction to Within-Person Analysis and RM ANOVA

STAT 3900/4950 MIDTERM TWO Name: Spring, 2015 (print: first last ) Covered topics: Two-way ANOVA, ANCOVA, SLR, MLR and correlation analysis

Introduction to Matrix Algebra and the Multivariate Normal Distribution

Univariate analysis. Simple and Multiple Regression. Univariate analysis. Simple Regression How best to summarise the data?

One-way ANOVA. Experimental Design. One-way ANOVA

610 - R1A "Make friends" with your data Psychology 610, University of Wisconsin-Madison

Advanced Quantitative Data Analysis

Recall that a measure of fit is the sum of squared residuals: where. The F-test statistic may be written as:

M A N O V A. Multivariate ANOVA. Data

On MANOVA using STATA, SAS & R

Machine Learning Linear Classification. Prof. Matteo Matteucci

ANCOVA. ANCOVA allows the inclusion of a 3rd source of variation into the F-formula (called the covariate) and changes the F-formula

ST430 Exam 2 Solutions

Chaper 5: Matrix Approach to Simple Linear Regression. Matrix: A m by n matrix B is a grid of numbers with m rows and n columns. B = b 11 b m1 ...

Workshop 7.4a: Single factor ANOVA

Variance Decomposition and Goodness of Fit

STA 450/4000 S: January

Density Temp vs Ratio. temp

General Linear Models. with General Linear Hypothesis Tests and Likelihood Ratio Tests

ESP 178 Applied Research Methods. 2/23: Quantitative Analysis

R Output for Linear Models using functions lm(), gls() & glm()

Biostatistics for physicists fall Correlation Linear regression Analysis of variance

Administration. Homework 1 on web page, due Feb 11 NSERC summer undergraduate award applications due Feb 5 Some helpful books

1 Introduction to Minitab

Structural Equation Modeling and Confirmatory Factor Analysis. Types of Variables

Course Introduction and Overview Descriptive Statistics Conceptualizations of Variance Review of the General Linear Model

Multiple Regression Part I STAT315, 19-20/3/2014

> modlyq <- lm(ly poly(x,2,raw=true)) > summary(modlyq) Call: lm(formula = ly poly(x, 2, raw = TRUE))

STAT 350: Summer Semester Midterm 1: Solutions

Stat 411/511 ESTIMATING THE SLOPE AND INTERCEPT. Charlotte Wickham. stat511.cwick.co.nz. Nov

Lecture 11 Multiple Linear Regression

Problem #1 #2 #3 #4 #5 #6 Total Points /6 /8 /14 /10 /8 /10 /56

Regression. Marc H. Mehlman University of New Haven

Section 4.6 Simple Linear Regression

Cheat Sheet: Linear Regression

Lecture 18: Simple Linear Regression

LDA, QDA, Naive Bayes

Part II { Oneway Anova, Simple Linear Regression and ANCOVA with R

1.) Fit the full model, i.e., allow for separate regression lines (different slopes and intercepts) for each species

Exam details. Final Review Session. Things to Review

A Re-Introduction to General Linear Models

Repeated-Measures ANOVA in SPSS Correct data formatting for a repeated-measures ANOVA in SPSS involves having a single line of data for each

Y (Nominal/Categorical) 1. Metric (interval/ratio) data for 2+ IVs, and categorical (nominal) data for a single DV

Analysing categorical data using logit models

Matrices and vectors A matrix is a rectangular array of numbers. Here s an example: A =

MS&E 226: Small Data

MULTIVARIATE ANALYSIS OF VARIANCE

SMA 6304 / MIT / MIT Manufacturing Systems. Lecture 10: Data and Regression Analysis. Lecturer: Prof. Duane S. Boning

Revision: Chapter 1-6. Applied Multivariate Statistics Spring 2012

A discussion on multiple regression models

Stat 5303 (Oehlert): Balanced Incomplete Block Designs 1

Biostatistics 380 Multiple Regression 1. Multiple Regression

BIOL 933!! Lab 10!! Fall Topic 13: Covariance Analysis

G562 Geometric Morphometrics. Statistical Tests. Department of Geological Sciences Indiana University. (c) 2012, P. David Polly

Simple, Marginal, and Interaction Effects in General Linear Models: Part 1

DISCOVERING STATISTICS USING R

Stat 5303 (Oehlert): Tukey One Degree of Freedom 1

Inferences for Regression

Classification: Linear Discriminant Analysis

STAT 501 Assignment 2 NAME Spring Chapter 5, and Sections in Johnson & Wichern.

Activity #12: More regression topics: LOWESS; polynomial, nonlinear, robust, quantile; ANOVA as regression

Course Introduction and Overview Descriptive Statistics Conceptualizations of Variance Review of the General Linear Model

Introduction to Logistic Regression

Regression and the 2-Sample t

Regression and Models with Multiple Factors. Ch. 17, 18

Online Appendix for Sterba, S.K. (2013). Understanding linkages among mixture models. Multivariate Behavioral Research, 48,

STAT 3022 Spring 2007

STAT 572 Assignment 5 - Answers Due: March 2, 2007

Variance Decomposition in Regression James M. Murray, Ph.D. University of Wisconsin - La Crosse Updated: October 04, 2017

R in Linguistic Analysis. Wassink 2012 University of Washington Week 6

Transcription:

ANOVA, ANCOVA and MANOVA as sem Robin Beaumont 2017 Hoyle Chapter 24 Handbook of Structural Equation Modeling (2015 paperback), Examples converted to R and Onyx SEM diagrams. This workbook duplicates some of the content in chapter 24 entitled A flexible Structural Equation Modeling Approach for Analyzing Means by Samuel B. Green and Marilyn S. Thompson. This workbook demonstrates the use the free Onyx software available from http://onyx.brandmaier.de/ The tab delimited datafiles are available from my webpage clicking the SEM course link at http://www.floppybunny.org/robin/web/rbook/ A collection of associated youtube videos can be found at https://goo.gl/pcpnoo. The original datafiles along with Mplus model files can be found at www.handbookofsem.com Contents 1 ANOVA... 2 2 MANOVA... 3 2.1 Multivariate normality... 3 2.2 Producing the Model... 4 2.3 SEM model... 5 2.4 Latent Variable approach... 8 3 Linear Discriminant Analysis (LDA)... 9 3.1 Histograms... 10 3.2 Confusion Matrix (table)... 10 Robin Beaumont 2017 robin@organplayers.co.uk Page 1

1 ANOVA To allow comparison between the traditional ANOVA/regression output and SEM I have done the first in R. As in Chapter 24 I have removed the intercept from the model to obtain the regression weights to equal the group means then repeated the analysis with the intercept to obtain the correct R squared value and ANOVA table. > # no intercept > model1 <- lm(after_stress ~ grp -1, data=one_way_anova_hoyle_chap24) > summary(model1) Call: lm(formula = after_stress ~ grp - 1,data =one_way_anova_hoyle_chap24)..... Coefficients: Estimate Std. Error t value Pr(> t ) grp1 24.333 1.422 17.12 8.23e-14 *** grp2 26.000 1.741 14.93 1.17e-12 *** grp3 31.333 1.422 22.04 5.33e-16 *** --- Now run a regression model with a intercept to get correct R squared values and ANOVA table > model1 <- lm(after_stress ~ grp, data=one_way_anova_hoyle_chap24) > summary(model1)........ Residual standard error: 4.265 on 21 degrees of freedom Multiple R-squared: 0.3815, Adjusted R-squared: 0.3226 F-statistic: 6.477 on 2 and 21 DF, p-value: 0.006442 > anova(model1) Analysis of Variance Table Response: after_stress Df Sum Sq Mean Sq F value Pr(>F) grp 2 235.62 117.81 6.4766 0.006442 ** Residuals 21 382.00 18.19 Working backwards we see that the -2 log likelihood ratio test produces the same value as that in the Green & Thompson chapter. We can also see that the unstandardized path coefficients (partial regression weights b s) equal the means as described by Green & Thompson. In R the R squared value from the intercept included model is correct. The onyx standardized path coefficient from the error term seems completely wrong, producing a R squared of (1-0.09 2 = 0.99) this is due to the fact that we have no intercept and analogous to the situation in R with the model with no intercept where the R squared value there was approximately 0.99. REMEMBER R squared values are inappropriate when no intercept is included, why this is so see two excellent answers here: http://stats.stackexchange.com/questions/7948/when-is-it-ok-toremove-the-intercept-in-a-linear-regression-model http://stats.stackexchange.com/questions/171240/how-can-r2-have-twodifferent-values-for-the-same-regression-without-an-inte/171250#171250 Robin Beaumont 2017 robin@organplayers.co.uk Page 2

2 MANOVA MANOVA makes the same assumptions as ANOVA plus multivariate normality (amongst the dependent variables). The data are shown below. Three groups (factor variable grp and indicators; g1, g2, g3) measured on four outcomes (y1, y2, y3, y4) n=200. Basic descriptive stats shown below. > summary(one_way_manova_hoyle_chap24) grp g1 g2 g3 y1 y2 1:60 Min. :0.0 Min. :0.0 Min. :0.0 Min. :14.00 Min. :44.00 2:60 1st Qu.:0.0 1st Qu.:0.0 1st Qu.:0.0 1st Qu.:23.00 1st Qu.:51.00 3:80 Median :0.0 Median :0.0 Median :0.0 Median :25.00 Median :54.00 Mean :0.3 Mean :0.3 Mean :0.4 Mean :25.25 Mean :54.15 3rd Qu.:1.0 3rd Qu.:1.0 3rd Qu.:1.0 3rd Qu.:27.00 3rd Qu.:56.25 Max. :1.0 Max. :1.0 Max. :1.0 Max. :36.00 Max. :64.00 y3 y4 Min. :32.00 Min. :22.00 1st Qu.:39.00 1st Qu.:32.00 Median :42.00 Median :34.00 Mean :41.45 Mean :34.26 3rd Qu.:44.00 3rd Qu.:37.00 Max. :51.00 Max. :47.00 Also useful we plot the distributions of the outcome variables for each group. dtalong <- stack(one_way_manova_hoyle_chap24, select=cbind(y1, y2, y3, y4)) dtalong <- data.frame(dtalong, grp=one_way_manova_hoyle_chap24$grp) names(dtalong); # values ind grp library(lattice) bwplot(values~grp ind, data=dtalong, layout = c(4,1)) # need 12 x values in 4 groups boxplot(values ~ grp + ind, at=c(1, 2, 3, 6, 7, 8, 10, 11, 12, 15, 16, 17), data = dtalong) Variable: y1 mean 1 24.61667 2 24.60000 3 26.22500 Variable: y2 mean 1 52.56667 2 54.45000 3 55.10000 Variable: y3 mean 1 40.58333 2 41.48333 3 42.07500 Variable: y4 mean 1 33.48333 2 33.68333 3 35.27500 There would appear to be a misprint on p. 404 a value for the means appears to have been transposed between the third and first column. I think 33.68 and 42.08 should be transposed, as shown opposite. 2.1 Multivariate normality There are various ways to check/ test this histograms of each dependent variable and scatterplots amongst the dependent variables are two informal ways. Bentlar (EQS software developer) prefers Mardia s multivariate normality test shown opposite obtained by using the mardiatest() function in the MVN package: Robin Beaumont 2017 robin@organplayers.co.uk Page 3

Many other tests for multivariate normality are available, and Andy Field likes the Shapiro-Wilk Test, which is the first one shown below. When applying these tests we hope for a non-significant result indicating that the variable does not show signs of violating multivariate normality. These tests are known to be overly sensitive so I would go with the Mardia test. 2.2 Producing the Model In R you use the lda() function in the MASS package to test to see if any of the dependent variables are markedly different from any of the others. All the measures below produce a significant p value indicating there is a difference between one or more of the outcomes (dependent variables). fit <- manova(cbind(y1,y2,y3,y4) ~ grp, data= one_way_manova_hoyle_chap24) summary(fit, intercept = FALSE, test="roy") # summary(fit, intercept = FALSE, test="pillai") # 'V' summary(fit, intercept = FALSE, test="hotelling") # 'T' summary(fit, intercept = FALSE, test="wilks") # lambda All these measures are significant therefore you would go on to analyse each separately. With a separate univariate ANOVA on each dependent variable, although the following SEM approach provides a more integrated approach. I will not follow up the ANOVA approach here. Robin Beaumont 2017 robin@organplayers.co.uk Page 4

2.3 SEM model Green & Thompson as usual present two models the Less constrained (LC) and the comparator, more constrained (MC) model (what you might want to think of as the null model). For the LC model they constrain the errors of the three levels of the factor i.e. var(eg1=eg2=eg3) to mimic the MANOVA model. Additionally for the MC model they restrict the path coefficients of each of the three indicator variables, ending up with just 4 path coefficients; 1x, 2x, 3x, and 4x between the independent and dependent variables. Before presenting either of the two above models I show below a completely unconstrained model. Notice that the constant is set to a fixed value of 1 to ensure that the unstandardized path values reflect the group means shown previously. Robin Beaumont 2017 robin@organplayers.co.uk Page 5

First the less constrained model. Here each level of the factor (input) has a unique estimate for each dependent variable (outcome). Robin Beaumont 2017 robin@organplayers.co.uk Page 6

And for the more constrained model we see that the paths are constrained to be equal for each dependent variable Robin Beaumont 2017 robin@organplayers.co.uk Page 7

2.4 Latent Variable approach Green & Thompson (p409-13) go on to develop a latent variable equivalent analysis to the previous MANOVA and I have attempted (!) to replicated some of it below. I would strongly suggest that you consult the original text if you are interested in following up this approach. Also my Youtube video of the paired t test provides some insight into how you can analyze the characteristics of a latent variable by saving its data. Opposite is shown the more constrained (null) model. The paths to the latent variable are set to zero in effect making them are equal. In additional I have also added a constant to the latent variable as it does not appear to be centered around zero in Onyx. For the less constrained model, shown below, I have allowed two of the paths from the groups (levels of the factor) to be estimated. I would then repeat the process selecting each of the other two levels in turn to be the reference level. We can see that comparing the first less constricted model to the null model above produces a highly significant p value indicating that one or both paths to the latent variable is not lightly to be equal to zero, in other words the mean of the latent variable is not zero Robin Beaumont 2017 robin@organplayers.co.uk Page 8

3 Linear Discriminant Analysis (LDA) From https://tgmstat.wordpress.com/2014/01/15/computing-and-visualizing-lda-in-r/ :..., Linear Discriminant Analysis (LDA) can be seen from two different angles. The first to classify a given sample of predictors to the class with highest posterior probability. It minimizes the total probability of misclassification. To compute it uses Bayes rule and assume that follows a Gaussian distribution with class-specific mean and common covariance matrix. The second tries to find a linear combination of the predictors that gives maximum separation between the centers of the data while at the same time minimizing the variation within each group of data. The second approach is usually preferred in practice due to its dimension-reduction property and is implemented in many R packages, as in the Ida() function of the MASS package for example. There is also a predict method implemented for lda objects. It returns the classification and the posterior probabilities of the new data based on the Linear Discriminant model. We would expect (by definition) LDA to provide better data separation compared to PCA, and this is exactly what we see. This kind of difference is to be expected since PCA tries to retain most of the variability in the data while LDA tries to retain most of the between-class variance in the data.... Note also that in this example [not shown] the first LD explains more than 99% of the between-group variance in the data while the first PC explains 73% of the total variability in the data. The aim is to reduce the number of variables (i.e. dimensions) which we can then use to develop a rule so that we can classify cases. See the example in the logistic regression chapter of my book for an example. Notably the To carry out a LDA on the data is just one line of code in R: discrim_model1 <- lda(grp ~ y1+y2+y3+y4, data = one_way_manova_hoyle_chap24) discrim_model1 Call: lda(grp ~ y1 + y2 + y3 + y4, data = one_way_manova_hoyle_chap24) Prior probabilities of groups: 1 2 3 0.3 0.3 0.4 Group means: y1 y2 y3 y4 1 24.61667 52.56667 40.58333 33.48333 2 24.60000 54.45000 41.48333 33.68333 3 26.22500 55.10000 42.07500 35.27500 Coefficients of linear discriminants: LD1 LD2 y1 0.01376133 0.26021307 y2-0.23845622-0.17091114 y3-0.03799657-0.08489168 y4-0.03212220 0.11657121 Proportion of trace: LD1 LD2 0.6936 0.3064 Things to note about the above output Prior probabilities shows the expected proportion of cases for each group based upon each groups size. Coefficients of linear discriminators these represent b weights in the regression. All values rather small and all but the first negative (small values) for the first linear discriminator. Both set of values for both Linear discriminators very similar suggesting that they will not do a very good job at dividing the cases into two groups! Proportion of trace The first value (0.69) indicates that LDS1 accounts for 69% of the variance while the second accounts for 31% You can also get the individual scores for each subject: my_predicts <- predict(discrim_model1) head(my_predicts$x,n= 10) LD1 LD2 1 1.2750835-1.66836302 2 1.0549508-0.04485330 3 0.5268578-0.98625677 4 0.2929609 0.27994437 5 2.6914822-0.64863282 Robin Beaumont 2017 robin@organplayers.co.uk Page 9

3.1 Histograms You can also obtain histograms of the LD scores, shown below indicating clearly there is very little separation of the scores Not good. ldahist(data = my_predicts$x[,1], g=one_way_manova_hoyle_chap24[,1]) We can also produce a quick and simple scatterplot of the LD scores indicating from which of the three groups in the independent variable each scores came, plot(discrim_model1) 3.2 Confusion Matrix (table) The confusion matrix provides a very intuitive approach to the results. The diagonal of the table indicates correct classifications while the off diagonals indicates misclassifications. > table(predict(discrim_model1, type="class")$class, one_way_manova_hoyle_chap24$grp) 1 2 3 1 26 15 14 2 11 12 9 3 23 33 57 Discriminant analysis is one of many approaches adopted by the Artificial Intelligence community and there are many subtleties/extensions not mentioned above. Robin Beaumont 2017 robin@organplayers.co.uk Page 10