lab3-5

pdf

School

Shri Ramdeobaba Kamla Nehru Engineering College *

*We aren’t endorsed by this school

Course

404

Subject

Statistics

Date

Nov 24, 2024

Type

pdf

Pages

5

Uploaded by SuperHumanButterfly1309

Report
12/12/23, 12:14 AM Getting started with statistics in R, Part 3 https://mattar.shinyapps.io/lab3/#section-two-sample-t-test 1/5 Two-sample -test When we have two groups and we want to compare the sample means against each other, we can run a two- sample -test , also referred to as a independent-samples -test . Example use cases of a one-sample -test: Do men and women run a mile at the same pace on average? Do households in rural vs urban communities have the same number of children, on average? Do cats and dogs sleep the same number of hours a day? Something to consider: Do our groups have equal variances? Which type of two-sample -test we run is dependent on whether or not the assumption of homogeneity of variance is met. Homogeneity of variance means that the two groups have the same amount of variability within them. That is, the data in one group has roughly the same amount of spread as the data in the other group, regardless of what the group means are. These data meet the assumption of homogeneity of variance These data do not meet the assumption of homogeneity of variance t t t t t Getting started with statistics in R, Part 3 Tutorial by Kelsey Moty Before you get started (https://mattar.shinyapps.io/lab3/#sectio before-you-get-started) Running basic inferential tests in R (https://mattar.shinyapps.io/lab3/#sectio running-basic-inferential-tests-in-r) -test (https://mattar.shinyapps.io/lab3/#sectio z-test) z One-sample -test (https://mattar.shinyapps.io/lab3/#sectio one-sample-t-test) t Two-sample -test (https://mattar.shinyapps.io/lab3/#sectio two-sample-t-test) t Paired-samples -test t Plotting our data Start Over
12/12/23, 12:14 AM Getting started with statistics in R, Part 3 https://mattar.shinyapps.io/lab3/#section-two-sample-t-test 2/5 Student’s two-sample -test If our data meets the assumption of homogeneity of variance, we can run a Student’s -test. Let’s check to see if our data meets this assumption. One way to do this is by looking at the ratio of variances to see if is roughly below 3. I have some code below that is going to group our data by condition and then calculate the variances for both the groups. The ratio of the variances is definitely under 3 ( ), so we should be set to run a student’s -test. To do so, we use the same t.test() function. We need to specify: 1. The formula ( dependent_variable ~ independent_variable ) 2. The dataset we are pulling the from ( data = ) 3. That the assumption of homogeneity has been met ( var.equal=TRUE ) t t R Code Start Over Run Code condition <chr> variance <dbl> generic 2.340643 specific 2.052223 2 rows data %>% group_by(condition) %>% summarize(variance = var(inferences)) 2.34/2.05 = 1.14 t 1 2 3 Getting started with statistics in R, Part 3 Tutorial by Kelsey Moty Before you get started (https://mattar.shinyapps.io/lab3/#sectio before-you-get-started) Running basic inferential tests in R (https://mattar.shinyapps.io/lab3/#sectio running-basic-inferential-tests-in-r) -test (https://mattar.shinyapps.io/lab3/#sectio z-test) z One-sample -test (https://mattar.shinyapps.io/lab3/#sectio one-sample-t-test) t Two-sample -test (https://mattar.shinyapps.io/lab3/#sectio two-sample-t-test) t Paired-samples -test t Plotting our data Start Over
12/12/23, 12:14 AM Getting started with statistics in R, Part 3 https://mattar.shinyapps.io/lab3/#section-two-sample-t-test 3/5 Just like with a one-sample -test, the output tells us a number of things: 1. What type of test we ran 2. What data we ran it on 3. Our -value, our degrees of freedom, and our -value 4. What our alternative hypothesis is 5. The lower and upper limits of a 95% Confidence Interval 6. The sample means (now we have two estimates because we have two groups) Welch’s two-sample -test However, if we didn’t meet the assumption of homogeneity, we would have to run a Welch’s -test instead. The way to do this in R is to simply specify var.equal=FALSE . R runs a Welch’s -test by default (if don’t set var.equal at all). R Code Start Over Run Code Two Sample t-test data: inferences by condition t = 6.9533, df = 356, p-value = 1.714e-11 alternative hypothesis: true difference in m eans between group generic and group specifi c is not equal to 0 95 percent confidence interval: 0.7807843 1.3966351 sample estimates: mean in group generic mean in group specifi c 2.75000 1.6612 9 t.test(inferences ~ condition, data = data, t t p t t t R Code Start Over Run Code t.test(inferences ~ condition, data = data, 1 2 3 1 2 3 Getting started with statistics in R, Part 3 Tutorial by Kelsey Moty Before you get started (https://mattar.shinyapps.io/lab3/#sectio before-you-get-started) Running basic inferential tests in R (https://mattar.shinyapps.io/lab3/#sectio running-basic-inferential-tests-in-r) -test (https://mattar.shinyapps.io/lab3/#sectio z-test) z One-sample -test (https://mattar.shinyapps.io/lab3/#sectio one-sample-t-test) t Two-sample -test (https://mattar.shinyapps.io/lab3/#sectio two-sample-t-test) t Paired-samples -test t Plotting our data Start Over
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
12/12/23, 12:14 AM Getting started with statistics in R, Part 3 https://mattar.shinyapps.io/lab3/#section-two-sample-t-test 4/5 What do you notice that’s different in the output? For one, the type of test R says we ran is different. It now says that we ran a Welch’s test. Two, the degrees of freedom are different. If you remember from class, a Welch’s test uses a much different formula for computing degrees of freedom (compared to a student’s test). Three, the -value is different. If the t-value is the same for the Student’s test and the Welch’s test, why do we have different levels of significance? When variances are unequal, the Welch's t-test oft Correct! Side note: When you submit your answer above, it will tell you your response is “correct” or “incorrect” after you submit it. Just ignore that message. It’s an artifact of the R package that I am using to build out this tutorial and I haven’t yet built out code that can override that message… Welch Two Sample t-test data: inferences by condition t = 6.9355, df = 348.77, p-value = 1.974e-11 alternative hypothesis: true difference in m eans between group generic and group specifi c is not equal to 0 95 percent confidence interval: 0.7799686 1.3974508 sample estimates: mean in group generic mean in group specifi c 2.75000 1.6612 9 p Getting started with statistics in R, Part 3 Tutorial by Kelsey Moty Before you get started (https://mattar.shinyapps.io/lab3/#sectio before-you-get-started) Running basic inferential tests in R (https://mattar.shinyapps.io/lab3/#sectio running-basic-inferential-tests-in-r) -test (https://mattar.shinyapps.io/lab3/#sectio z-test) z One-sample -test (https://mattar.shinyapps.io/lab3/#sectio one-sample-t-test) t Two-sample -test (https://mattar.shinyapps.io/lab3/#sectio two-sample-t-test) t Paired-samples -test t Plotting our data Start Over
12/12/23, 12:14 AM Getting started with statistics in R, Part 3 https://mattar.shinyapps.io/lab3/#section-two-sample-t-test 5/5 If we have unequal variances, which type of t-test should we run? Correct! Previous Topic Next Topic Student’s t-test Welch’s t-test Getting started with statistics in R, Part 3 Tutorial by Kelsey Moty Before you get started (https://mattar.shinyapps.io/lab3/#sectio before-you-get-started) Running basic inferential tests in R (https://mattar.shinyapps.io/lab3/#sectio running-basic-inferential-tests-in-r) -test (https://mattar.shinyapps.io/lab3/#sectio z-test) z One-sample -test (https://mattar.shinyapps.io/lab3/#sectio one-sample-t-test) t Two-sample -test (https://mattar.shinyapps.io/lab3/#sectio two-sample-t-test) t Paired-samples -test t Plotting our data Start Over