
Residual Analysis for ANOVA Models Chapter 18 KNNL
Learn about residual analysis for ANOVA models, detecting model departures, effects of model departures, an example of virtual training for lifeboat tasks, and tests for constant variance. Understand how to identify and address issues such as non-constant variance, lack of independence in errors, and non-normal data in ANOVA models.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Residual Analysis for ANOVA Models KNNL Chapter 18
Residuals Model Errors (unobserved): ^ = = e Y Y Y Y ij i ij ij i 1 1 1 n n n ij E e ij e ij e ij s e = = = = 2 2 2 0 i i i s MSE MSE n n n i i i Semi-Studentized Residual (Residual divided by estimate of ,trivial to compute): e MSE ij = * ij e Studentized Residual (Residual divided by its standard error, messier to compute): e r n MSE n ij = ij 1 i i Studentized Deleted Residual: 1/2 1 n r = t e T ij ij 1 n 2 ij SSE e i n i
Model Departures Detected With Residuals and Plots Errors have non-constant variance Errors are not independent Existence of Outlying Observations Omission of Important Predictors Non-normal Errors Common Plots Residuals versus Treatment Residuals versus Treatment Mean Aligned Dot Plot (aka Strip Chart) Residuals versus Time (when data collected in time order) Residuals versus Omitted Variables Box Plots, Histograms, Normal Probability Plots
Effects of Model Departures Non-normal Data Generally not problematic in terms of the F-test, if data are not too far from normal, and reasonably large sample sizes Unequal Error Variances As long as sample sizes are approximately equal, generally not a problem in terms of F-test. Non-independence of error terms Can cause problems with tests. Should use Repeated Measures ANOVA if same subject receives each treatment
Example Virtual Training of Lifeboat Task Treatments r = 4 Methods of Virtual Training Traditional Lecture and Materials (LEC/MAT) Computer Monitor / Keyboard (MON/KEY) Head Mounted Display / Joypad (HMD/JPD) Head Mounted Display / Wearable Sensors (HMD/WEA) Response (Y) Procedural Knowledge Test Score n = 16 subjects per treatment (Data generated to match) Trt 1 2 3 4 Label LEC/MAT MON/KEY HMD/JOY HMD/WEA n 16 16 16 16 Mean 4.931 7.708 6.736 6.875 SD 1.94 1.43 2.82 1.99 Source: J. Jung and Y.J. Ahn (2018). Effects of Interface on Procedural Skill Transfer in Virtual Training: Lifeboat Launching Operation Study, Computer Animation & Virtual Worlds, 29, e1812. https://doi.org/10.1002/cav.1812
Tests for Constant Variance H0:12=...=r2 Hartley's Test: (Assumes normal data, equal sample sizes) ( ) ( ) i s 2 i max s ( ) = ; , r n = = = * * Reject if 1 1 where ... H H H H n n n 0 1 r 2 min ( ) i s ( ) i s = = = = = = 2 2 2 2 Example: 4 16 max 2.82 7.9524 min 1.43 2.0449 r n ( ) ( ) i s 2 i max s 7.95 2.0449 24 ( ) ( ) = = = ; , r n = = * 3.889 1 1 .95;4,15 4.01 H H H 2 min Brown-Forsythe (aka Levene) Test: (Robust to non-normality, allows unequal sample sizes) ( ) ~ ~ = = = = 1,..., 1,..., median ,..., d Y Y i r j n Y Y Y 1 ij ij i i i i in i n n n ( ) r r ( ) r 2 i i i 2 d d d d n d d ij i i ij ij i = = = = = 1 n 1 1 1 1 j i j i j = = = = = 1 i d d MSTR MSE i BF BF 1 n r n r i T T MSTR MSE ( ) = * * Reject if 1 ; 1, F H F F r n r BF 0 BF T BF
Bartletts Test General Test that can be used in many settings with groups H0: 12= = t2 (homogeneous variances) Ha: Population Variances are not all equal MSE Pooled Variance 1 C t ) ( ) 1 ln ( ) ( ln ) ( = 2 B 2 i : TS X N t MSE n s i = 1 i 1 t 1 1 t = + 1 C ( ) 3 1 1 n N t = 1 i i ( ) 2 B 2 2 t 2 B : P-value: RR X P X ; 1 t 1
R Program ### Levene's and Bartlett's Tests of Equal Variances ## Levene's Test (in car package) install.packages("car") library(car) leveneTest(procKnow, grp.trt, "median") ## Bartlett's Test bartlett.test(procKnow ~ grp.trt) > leveneTest(procKnow, grp.trt, "median") Levene's Test for Homogeneity of Variance (center = "median") Df F value Pr(>F) group 3 2.1463 0.1038 60 > bartlett.test(procKnow ~ grp.trt) Bartlett test of homogeneity of variances data: procKnow by grp.trt Bartlett's K-squared = 6.7626, df = 3, p-value = 0.07986
Remedial Measures Normally distributed, Unequal variances Use Weighted Least Squares with weights: wij = 1/si2 ( ) ( ) ( ) * Conclude means not all equal if 1 T r n r SSE R SSE F SSE F ( ) = * w w w 1 ; 1, F F F r n r w w T Welch s Test Non-normal data (with possibly unequal variances) Variance Stabilizing and Box-Cox Transformations Variance proportional to mean: Y =sqrt(Y) Standard Deviation proportional to mean: Y =log(Y) Standard Deviation proportional to mean2: Y =1/Y Response is a (binomial) proportion: Y =2arcsin(sqrt(Y)) Non-parametric tests F-test based on ranks and Kruskal-Wallis Test
Example Weighted Least Squares Virtual Training vt <- read.csv("http://users.stat.ufl.edu/~winner/data/virtual_training.csv") attach(vt); names(vt) grp.trt <- factor(grp.trt) ## Obtain treatment sample sizes and variances n.trt <- as.vector(tapply(procKnow, grp.trt, length)) var.trt <- as.vector(tapply(procKnow, grp.trt, var)) ## String out weights = 1/var so that weight i is replicated n_i times virt.wt <- rep(1/var.trt, n.trt) ## Weighted Least Squares ANOVA aov.wt <- aov(procKnow ~ grp.trt, weight=virt.wt) anova(aov.wt) > anova(aov.wt) Analysis of Variance Table Response: procKnow Df Sum Sq Mean Sq F value Pr(>F) grp.trt 3 21.32 7.1065 7.1065 0.0003655 *** Residuals 60 60.00 1.0000
Welchs Test Unequal Variances n s t = = i w w w i i 2 i = 1 i 2 t wY i i 1 t 2 i = = 1 i * F wY i 1 t w = 1 i ( t ) 1 2 2 2 1 t 1 w w t = = + 1 1 i C m C W W W 2 1 n = 1 i i 1 3 approx ~ = = * C F m F F 1, W W W W t 2 1 t W
Example Virtual Training of Lifeboat Task Trt n ybar s s^2 w=n/s^2 w*ybar 4.2512 7.8243 2.0120 4.0403 18.1279 122.6027 850.4959 w*ybar^2 C_W 1 2 3 4 16 16 16 16 4.931 7.708 6.736 6.875 1.94 1.43 2.82 1.99 3.7636 2.0449 7.9524 3.9601 20.9629 103.3681 60.3100 464.8698 13.5526 27.7771 190.9674 0.0391 0.0215 0.0527 0.0403 0.1536 91.2906 sum 2 r wY ( ) i 2 i 122.6027 18.1279 1 1 r 2 i = = = = 1 i * 850.4949 7.1026 F wY i 1 4 1 r w = 1 i 2 1 w w r = = 1 0.1536 i C W 1 n = 1 i i ( r ) ( 4 )( 1 2 2 1 2 4 2 r ) = + = + = 1 1 0.1536 0.9607 m C W W 2 2 1 1 1 3 3 ( ) ( ) = = = = = = * 0.1536 32.55 0.9607 7.1026 6.8235 C F m F W W W W 2 2 1 2.896 = 4 1 k ( = ) ( ) qf .95,3,32.55 in R 0.95,3,32.55 F ( ) ( ) ( ) 6.8235 0.0011 1-pf 6.8235,3,32.55 in R P F 3,32.55
R Commands with oneway.test Function oneway.test(procKnow ~ grp.trt, var.equal=F) > oneway.test(procKnow ~ grp.trt, var.equal=F) One-way analysis of means (not assuming equal variances) data: procKnow and grp.trt F = 6.827, num df = 3.000, denom df = 32.562, p-value = 0.001072
Nonparametric Tests Rank all observations across treatments from 1 to ,assigning average ranks when ties occur n T n n r i i R R ( ) + ij ij 1 ... + + + 1 2 n n 1 n n = = = 1 n 1 1 j i j = = = = = T T n R R T T i 2 n n i T T T n in ( ) ( ) ( ) r r r 2 2 2 i = = = SSTO R R SSTR n R R SSE R R i i R ij R i R ij = = = = = 1 1 1 1 1 i j i i j (Approximate) = : F test ( ) ) 1 r SSTR SSE r MSTR MSE ( ) R = * * Conclude means not all equal if 1 ; 1, F F F r n r R ( R R T n R R T ( ) + 1 n n ( ) 1 n 1 n ( ) ( ) + T T Simultaneous CIs for Differences in Mean Ranks: 1 / 2 R R z g ' i i 12 ' i i Kruskal-Wallis Test (Directly computed in most software packages): = + + 2 i 12 n R n r SSTR SSTO n ( ) ( ) = 2 KW 2 KW 2 3 1 Conclude means not all equal if 1 ; 1 X n X r R ( ) T 1 n = 1 i T T i R 1 T
Example Virtual Training of Lifeboat Task PKScore1 PKScore2 PKScore3 PKScore4 Rank1 4.5614 5.4532 6.6593 8.9208 5.6427 8.3489 6.4394 8.3175 4.8635 9.7848 0.3268 6.2697 5.699 7.1327 6.3545 7.0886 6.7509 5.0733 6.6019 8.3865 3.2365 9.4227 6.1655 8.9142 2.406 8.515 1.9851 6.8198 5.2198 8.639 5.9765 6.2467 Rank2 Rank3 Rank4 1.8773 6.1884 6.8029 9.4535 8.7312 6.4198 8.4955 5.9008 3.3336 1.653 9.471 7.2818 9.7649 3.4931 8.9848 9.9261 9.8257 8.9988 5.4112 4.9396 8.6486 5.1459 7.0656 7.9552 5.7284 6.6314 7.5014 8.2456 4.2465 3.2286 6.552 9.8754 11 34 19 30 12 1 20 28 35 32 7 24 5 4 16 23 301 18 54 46 45 61 27 40 39 14 47 57 53 49 37 50 26 663 3 62 56 17 13 51 15 38 43 21 33 42 44 10 6 31 63 545 25 36 58 52 29 48 22 8 2 59 41 60 9 55 64 571 Sum : Teaching Medians are all Equal = + = ( : Teaching Medians not all equal + H H 0 A 2 2 2 2 12 (301) 16 (663) 16 (571) 16 (545) 16 + + + = 207.92 195 12.92 = . .: T S H 3(64 1) ( ) 64 64 1 2 .95,4 1 = = . .( R R 0.05): 7.815 ) = H 2 value: 12.92 0.0048 P P H 3
R Commands kruskal.test Function kruskal.test(procKnow ~ grp.trt) > kruskal.test(procKnow ~ grp.trt) Kruskal-Wallis rank sum test data: procKnow by grp.trt Kruskal-Wallis chi-squared = 12.915, df = 3, p-value = 0.004824