Survey

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Transcript

Research Methods I T-tests Different Kinds of T-tests One sample t-test When population variance is not known Two sample t-test for independent samples Compare two sample means Samples are independent of each other Two sample t-test for dependent samples Compare two sample means Samples are paired / dependent One-Sample T-test One-sample t-test is being used when µ is known but σ is not known. For the one-sample t-test σ is being substituted with σ(hat) otherwise it is exactly the same as the z-test Same formula as for standard deviation but we divide by n-1 This is especially important when the sample size is small; with large samples it makes little difference whether s or σ is being used. In order to calculate t: t = xbar - µ / σhat / √n T-distribution The sampling distributions of z and t are different. For z-tests the sampling distribution of sample means is a normal curve For t-tests the sampling distribution changes according to sample size (above n=120 almost like z distribution) The smaller n the flatter the curve, the larger the tails and the higher the critical t-value in order to reject the null hypothesis. For n > 120 tcritical is 1.658 while zcritical is 1.645 For n = 6 tcritical is 2.015 while zcritical is still 1.645 Table on page 251 gives critical t-values for each sample size (better degrees of freedom: n-1) Degrees of Freedom The critical value for t depends on the degrees of freedom (df) Degrees of freedom depend on the sample size df = n-1 All tables of critical values of significance tests Degrees of freedom tell us how many numbers are free to vary. If we have x1 + x2 + x3 = 10 only two of the three numbers are free to vary the last one has to be a certain way to get the fixed result: here there are two degrees of freedom Two-sample t-tests In two-sample t-tests two sample means are being compared. What is the probability that the difference in the means that is observed is due to chance? Population parameters are no longer known Normal distribution of population must be assumed unless sample size is very large There are basically two kinds of t-tests Dependent Independent Dependent vs Independent Samples Independent samples: Assumes that composition of one sample is independent from composition of other sample. Both samples reflect different populations H0: µ1= µ2 H1: µ1≠ µ2 or µ1< µ2 or µ1> µ2 Sample size (n), sample mean, and sample variance have to be known for each sample If two random samples are collected and one has had a treatment exposure only the treatment exposure should make the difference between the two groups. Dependent vs Independent Samples Dependent samples: Members of one sample are matched or paired in some way with members of the other sample Examples are pairs of twins, husband and wife, repeated measures experiment (get a person’s measure before and after a treatment) T-test for Independent Samples T-test for independent samples is based on distribution of differences between means. It is like the t-distribution except using the differences between means In order to calculate t we get the difference between the two sample means, and divide it by the standard deviation of the sampling distribution (the standard error) However, standard error for this distribution is based on differences of means and is therefore different. T-test for Independent Samples 1. Write out null and alternative hypothesis for the original problem. 2. For each sample determine its sample size, its mean, and its variance 3. To determine which t formula to use fothe F test for homogeneity of variance 4. Perform the appropriate F test T-tests for Independent Samples The standard error for our distribution is based on variances of two samples. If both variances are close in magnitude we can calculate the pooled estimate of common variance. This is based on a weighted average of our two sample variances. If both variances are not close in magnitude we have to use a different formula for the ttest F-test for homogeneity of variance The F-test for homogeneity of variance tells us whether the variance between both samples is similar or different 1. 2. 3. 4. 5. Write out the null and alternative hypothesis for the F test Calculate F and its two degrees of freedom Compare the F value with Fcritical If your F value is smaller than Fcritical then assume equal population variances. If your F value is larger than Fcritical then assume unequal population variances. F-test for homogeneity of variance H0 : variance of sample 1 is equal to variance of sample 2 H1 : variance of sample 1 is not equal to variance of sample 2 F tests are always non-directional F = larger of the two sample variances divided by the smaller of the two sample variances Degrees of freedom for both numerator and denominator: df = n – 1 F-table gives critical values n1 = numerator degrees of freedom SAS for Paired T-tests data new; set work.julia20; diff = final_exam - mid_term_exam; run; proc print; var diff; run; proc means n mean stderr t prt; var diff; run; N 12 The MEANS Procedure Analysis Variable : diff Mean Std Error t Value Pr > |t| -4.0000000 1.1742180 -3.41 0.0059 For dependent sample t-test we run a proc means with the options n, mean, stderr, t, and prt These statistics will be computed for the difference variable T will give the t-value and its probability, testing the null hypothesis that the variable DISS comes from a population whose mean is zero. The mean gives the average difference score. If p<.05 we can say that the two groups are significantly different from one another. ANOVA: Analysis of Variation The basic ANOVA situation Two variables: 1 Categorical, 1 Quantitative Main Question: Do the (means of) the quantitative variables depend on which group (given by categorical variable) the individual is in? If categorical variable has only 2 values: • 2-sample t-test ANOVA allows for 3 or more groups An example ANOVA situation Subjects: 25 patients with blisters Treatments: Treatment A, Treatment B, Placebo Measurement: # of days until blisters heal Data [and means]: • A: 5,6,6,7,7,8,9,10 [7.25] • B: 7,7,8,9,9,10,10,11 [8.875] • P: 7,9,9,10,10,10,11,12,13 [10.11] Are these differences significant? Informal Investigation Graphical investigation: • side-by-side box plots • multiple histograms Whether the differences between the groups are significant depends on • the difference in the means • the standard deviations of each group • the sample sizes ANOVA determines P-value from the F statistic Side by Side Boxplots 13 12 11 days 10 9 8 7 6 5 A B treatment P What does ANOVA do? At its simplest (there are extensions) ANOVA tests the following hypotheses: H0: The means of all the groups are equal. Ha: Not all the means are equal doesn’t say how or which ones differ. Can follow up with “multiple comparisons” Note: we usually refer to the sub-populations as “groups” when doing ANOVA. Assumptions of ANOVA each group is approximately normal check this by looking at histograms and/or normal quantile plots, or use assumptions can handle some nonnormality, but not severe outliers standard deviations of each group are approximately equal rule of thumb: ratio of largest to smallest sample st. dev. must be less than 2:1 Normality Check We should check for normality using: • assumptions about population • histograms for each group • normal quantile plot for each group With such small data sets, there really isn’t a really good way to check normality from data, but we make the common assumption that physical measurements of people tend to be normally distributed. Standard Deviation Check Variable days treatment A B P N 8 8 9 Mean 7.250 8.875 10.111 Compare largest and smallest standard deviations: • largest: 1.764 • smallest: 1.458 • 1.458 x 2 = 2.916 > 1.764 Note: variance ratio of 4:1 is equivalent. Median 7.000 9.000 10.000 StDev 1.669 1.458 1.764 Notation for ANOVA • n = number of individuals all together • I = number of groups • = mean for entire data set is x Group i has • ni = # of individuals in group i • xij = value for individual j in group i • = mean for group i • si = standard deviation for group i xi How ANOVA works (outline) ANOVA measures two sources of variation in the data and compares their relative sizes • variation BETWEEN groups • for each data value look at the difference between its group mean and the overall mean x i x 2 • variation WITHIN groups • for each data value we look at the difference between that value and the mean of its group x xi 2 ij The ANOVA F-statistic is a ratio of the Between Group Variaton divided by the Within Group Variation: Between MSG F Within MSE A large F is evidence against H0, since it indicates that there is more difference between groups than within groups. Minitab ANOVA Output Analysis of Variance for days Source DF SS MS treatment 2 34.74 17.37 Error 22 59.26 2.69 Total 24 94.00 F 6.45 P 0.006 R ANOVA Output treatment Residuals Df Sum Sq Mean Sq F value Pr(>F) 2 34.7 17.4 6.45 0.0063 ** 22 59.3 2.7 How are these computations made? We want to measure the amount of variation due to BETWEEN group variation and WITHIN group variation For each data value, we calculate its contribution to: • BETWEEN group variation: • WITHIN group variation: x x 2 i ( xij xi ) 2 An even smaller example Suppose we have three groups • Group 1: 5.3, 6.0, 6.7 • Group 2: 5.5, 6.2, 6.4, 5.7 • Group 3: 7.5, 7.2, 7.9 We get the following statistics: SUMMARY Groups Column 1 Column 2 Column 3 Count Sum Average Variance 3 18 6 0.49 4 23.8 5.95 0.176667 3 22.6 7.533333 0.123333 Excel ANOVA Output ANOVA Source of Variation SS Between Groups 5.127333 Within Groups 1.756667 Total 6.884 df MS F P-value F crit 2 2.563667 10.21575 0.008394 4.737416 7 0.250952 9 1 less than number of groups 1 less than number of individuals (just like other situations) number of data values number of groups (equals df for each group added together) Computing ANOVA F statistic data group 5.3 1 6.0 1 6.7 1 5.5 2 6.2 2 6.4 2 5.7 2 7.5 3 7.2 3 7.9 3 TOTAL TOTAL/df group mean 6.00 6.00 6.00 5.95 5.95 5.95 5.95 7.53 7.53 7.53 WITHIN difference: data - group mean plain squared -0.70 0.490 0.00 0.000 0.70 0.490 -0.45 0.203 0.25 0.063 0.45 0.203 -0.25 0.063 -0.03 0.001 -0.33 0.109 0.37 0.137 1.757 0.25095714 overall mean: 6.44 BETWEEN difference group mean - overall mean plain squared -0.4 0.194 -0.4 0.194 -0.4 0.194 -0.5 0.240 -0.5 0.240 -0.5 0.240 -0.5 0.240 1.1 1.188 1.1 1.188 1.1 1.188 5.106 2.55275 F = 2.5528/0.25025 = 10.21575 Minitab ANOVA Output Analysis of Variance for days Source DF SS MS treatment 2 34.74 17.37 Error 22 59.26 2.69 Total 24 94.00 F 6.45 P 0.006 # of data values - # of groups 1 less than # of groups (equals df for each group added together) 1 less than # of individuals (just like other situations) Minitab ANOVA Output Analysis of Variance for days Source DF SS MS treatment 2 34.74 17.37 Error 22 59.26 2.69 Total 24 94.00 (x ij xi ) obs 2 (x ij x) (x 2 obs obs SS stands for sum of squares • ANOVA splits this into 3 parts F 6.45 P 0.006 i x) 2 Minitab ANOVA Output Analysis of Variance for days Source DF SS MS treatment 2 34.74 17.37 Error 22 59.26 2.69 Total 24 94.00 MSG = SSG / DFG MSE = SSE / DFE F = MSG / MSE (P-values for the F statistic are in Table E) F 6.45 P 0.006 P-value comes from F(DFG,DFE) So How big is F? Since F is Mean Square Between / Mean Square Within = MSG / MSE A large value of F indicates relatively more difference between groups than within groups (evidence against H0) To get the P-value, we compare to F(I-1,n-I)-distribution • I-1 degrees of freedom in numerator (# groups -1) • n - I degrees of freedom in denominator (rest of df) Connections between SST, MST, and standard deviation If ignore the groups for a moment and just compute the standard deviation of the entire data set, we see s 2 x ij x n 1 SST 2 DFT MST So SST = (n -1) s2, and MST = s2. That is, SST and MST measure the TOTAL variation in the data set. Connections between SSE, MSE, and standard deviation Remember: si 2 x xi 2 ij ni 1 SS[ Within Group i ] dfi So SS[Within Group i] = (si2) (dfi ) This means that we can compute SSE from the standard deviations and sizes (df) of each group: SSE SS[Within] SS[Within Group i ] s (ni 1) s (dfi ) 2 i 2 i Pooled estimate for st. dev One of the ANOVA assumptions is that all groups have the same standard deviation. We can estimate this with a weighted average: 2 2 2 (n 1)s (n 1)s ... (n 1)s 1 2 2 I I s2p 1 nI (df1)s (df 2 )s ... (df I )s s df1 df 2 ... df I 2 p SSE s MSE DFE 2 p 2 1 2 2 2 I so MSE is the pooled estimate of variance In Summary SST (x ij x ) s (DFT) 2 2 obs SSE (x ij x i ) si (df i ) 2 2 obs groups SSG (x i x) 2 obs n (x i i x) 2 groups SS MSG SSE SSG SST; MS ; F DF MSE 2 R Statistic R2 gives the percent of variance due to between group variation SS[Between ] SSG R SS[Total ] SST 2 We will see R2 again when we study regression. Where’s the Difference? Once ANOVA indicates that the groups do not all appear to have the same means, what do we do? Analysis of Variance for days Source DF SS MS treatmen 2 34.74 17.37 Error 22 59.26 2.69 Total 24 94.00 Level A B P N 8 8 9 Pooled StDev = Mean 7.250 8.875 10.111 1.641 StDev 1.669 1.458 1.764 F 6.45 P 0.006 Individual 95% CIs For Mean Based on Pooled StDev ----------+---------+---------+-----(-------*-------) (-------*-------) (------*-------) ----------+---------+---------+-----7.5 9.0 10.5 Clearest difference: P is worse than A (CI’s don’t overlap) Multiple Comparisons Once ANOVA indicates that the groups do not all have the same means, we can compare them two by two using the 2-sample t test • We need to adjust our p-value threshold because we are doing multiple tests with the same data. •There are several methods for doing this. • If we really just want to test the difference between one pair of treatments, we should set the study up that way. Tuckey’s Pairwise Comparisons Tukey's pairwise comparisons Family error rate = 0.0500 Individual error rate = 0.0199 95% confidence Use alpha = 0.0199 for each test. Critical value = 3.55 Intervals for (column level mean) - (row level mean) A B -3.685 0.435 P -4.863 -0.859 B These give 98.01% CI’s for each pairwise difference. -3.238 0.766 98% CI for A-P is (-0.86,-4.86) Only P vs A is significant (both values have same sign) Tukey’s Method in R Tukey multiple comparisons of means 95% family-wise confidence level diff lwr upr B-A 1.6250 -0.43650 3.6865 P-A 2.8611 0.85769 4.8645 P-B 1.2361 -0.76731 3.2395