Paired t-Test in R with Examples | R Tutorial 4.7 | MarinStatsLectures

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии • 55

  • @marinstatlectures
    @marinstatlectures  5 лет назад +6

    🦄 In this #R video we learn to run the paired t-test in R for the means of two paired (dependent) populations (with example). Common applications of the paired sample t-test include case-control studies or repeated-measures designs. We recommend watching these #Statistics videos on the concept of Paired t-Test: ruclips.net/video/Q0V7WpzICI8/видео.html and Wilcoxon Signed Rank Test : ruclips.net/video/v4ZHlTbTOK8/видео.html to learn the concepts better! You can find R practice dataset (BloodPressure) used in this tutorial here: (statslectures.com/r-scripts-datasets ); Want to support us? You can Donate (bit.ly/2CWxnP2), Share Our Videos, Leave Comments and give us a Like 👍🏼! Either way we thank you 😊

  • @strossicro1
    @strossicro1 5 лет назад

    Watcher 2:07 minutes soo far. Paused to commend you. Your lecturing style and tempo is very clear and easy to follow, thank you! Hvala Marine!

  • @sherizamohd1441
    @sherizamohd1441 10 лет назад +5

    Thank you this video is very helpful, and contained lots of information

  • @raguspag55
    @raguspag55 8 лет назад +3

    Very clear! Just signed up. Will be looking at your vids while taking a class

  • @RoghyM
    @RoghyM 11 месяцев назад

    This video helped me a lot. Thank you

  • @DragonWhisky
    @DragonWhisky 4 года назад

    Thank you for showing us the knowledge, it is very valuable to me.

  • @mariambenmoussa901
    @mariambenmoussa901 10 лет назад +2

    Thank you for the tutorial!

  • @abrahamsibi
    @abrahamsibi 6 лет назад +2

    excellent explaination

  • @marcoventura9451
    @marcoventura9451 4 года назад

    Very good video, by the way you teach how to "add a column filed" in R with cbind(). I am new to R and I would say that Adding and computing a column/filed is an easy task in access, oracle, sql server, spss, sas, and so on... in R is not so straightforward as you can see googling "add a column in r data frame": I understand that there are a few different methods depending on the specific package used, in R base is cbind(). I computed the column Diff=After-Before and binded to the BloodPressure data frame and conducted the t test on this field, obtaining the same results as the t test in the video.

    • @marinstatlectures
      @marinstatlectures  4 года назад +1

      If you use the *mutate()* command I. The *tidyverse* packages, it is much simpler. Mutate essentially creates a new variable using existing variables in the data, and will attach it as a new column to the data. The *tidyverse* has, for the most part, sought to make commands and coding in R clearer and more logical

    • @marcoventura9451
      @marcoventura9451 4 года назад

      @@marinstatlectures Thank You Marin! It's a bit messy getting oriented in R packages, I will try tidyverse as you suggest.

  • @mane_gnona
    @mane_gnona 11 лет назад +2

    Thank you for the video. it is really helpful

    • @marinstatlectures
      @marinstatlectures  11 лет назад

      Hi TheChicomito, you're very welcome, glad we could help!

  • @yuliaegorova589
    @yuliaegorova589 3 года назад

    i wonder if we need to do p values adjustment here as we do test multiple times by comparing each pair of the data, so there is a big chance to have a false positive

  • @dimitrispavlakis2590
    @dimitrispavlakis2590 9 лет назад +2

    Great tutorial :)

  • @cassandrag7944
    @cassandrag7944 9 лет назад +3

    You are a wizard. Please come lecture at UQ. We have only muggles.

    • @marinstatlectures
      @marinstatlectures  9 лет назад +1

      lol thanks +Cassandra G ! i'm lecturing at UBC, so if you feel like crossing an ocean, you can come take my courses here :)

    • @rockstarvarun1995
      @rockstarvarun1995 7 лет назад

      hahaha Mike ;)

  • @haivu1214
    @haivu1214 3 года назад

    Hi Sir,
    I wonder why my boxplot give me 25 box rather than 2 as your.
    Thank you

  • @vasanthkrishnan788
    @vasanthkrishnan788 6 лет назад +2

    it is very useful thank you and why using plot sir

  • @WiskeyFire
    @WiskeyFire 5 лет назад +1

    Starts at 2:18

  • @AiurMedia
    @AiurMedia 7 лет назад

    t falls in the 99 percent interval, does it mean the hypothesis of before and after have the same mu is true?

  • @manojpatil2457
    @manojpatil2457 4 года назад

    Hi Mike, Hope you are doing great!
    When I plot any figure particularly for this video, I am getting too tight plots, I mean the I am not getting vertical dimensions as large as yours, May I know what exactly am I might be doing wrong?

  • @MichaelAndrew2013
    @MichaelAndrew2013 3 года назад

    This was wonderfully helpful, thank you! I'm trying to figure out when it's appropriate to code for a random effect and when not to. With the data set that you presented, would it be effective to run a linear mixed model with the subject as the random effect? If not, why?

  • @XxTiMa201xX
    @XxTiMa201xX 4 года назад

    How would you do a Levene Test here? There's no groups...

  • @Jauntygibbon
    @Jauntygibbon 8 лет назад +1

    hey dude your videos have helped me out no end with my uni work. thank you very much.
    if you answer this it'll be an even bigger help. I don't know if my stats are just wrong and that's why i'm struggling i dunno. basically :-
    i want to to see if "shade type" (heavy / none) has an effect on the dry biomass of plants leaves and stems ("dry leaves" / "dry stems").
    so i have all the mass measurements for the two dry tissues, and I'm trying to compare them to shade type.
    do i need to perform tests separately for i) Shade Type vs Dry Leaves ii) Shade Type vs Dry Stems
    OR
    is there a way of incorporating them both together?
    Sam

    • @fintaneh
      @fintaneh 8 лет назад

      I'm doing a similar style of study, change in patient weight after an intervention. In each case, find the difference in mass for the plant (after-before) then run the t test on that data: change in mass in the shaded group vs change in mass in the unshaded group. Seem reasonable?

  • @abhinavgupta3632
    @abhinavgupta3632 7 лет назад +2

    Thank you this was a wonderful tutorial . I am still confused , how do we qualify the data as paired or independent ?

    • @marinstatlectures
      @marinstatlectures  7 лет назад +3

      as an example, if the same people are measured under 2 different conditions, then their measurements in the two different conditions are parked (or dependant). since they are the same people, their measurements under the different conditions will be correlated. if, instead, you are measuring different people under the different conditions, then the measurements will be independent. the main to think is are you repeatedly measuring the same people? if so, then their measurements will be dependent/paired/related.

    • @abhinavgupta3632
      @abhinavgupta3632 7 лет назад

      Thank you , very well explained !

  • @sherizamohd1441
    @sherizamohd1441 10 лет назад

    I just started watching your lecture today, and with your lecture i did many graphs and perhaps very happy to know that R is very convenient than other that i learned. But i face i problem, with my Boxplots. I manage to draw full boxplot for my data but not for one parameter, such as you showed in your lecture, e.g Smokers...Why?The error message was object 'xy' not found...

  • @Lyn-eg3id
    @Lyn-eg3id 10 лет назад

    Hello. This video is really helpful. I wondered if you could specify how to interpret the results. I ran my statistics while watching this, and was able to get the print out, but am not sure I am interpreting the results. I recoded the data that I have. I am also not sure but it seems as though my students did worst in the "after" data, but this is not the case.

    • @marinstatlectures
      @marinstatlectures  10 лет назад

      Hi Lynette 3132 . sure, here's what's in the output. the t-value and p-value are for the null hypothesis that the the different in means is 0 (that there is no difference in mean before and after). The confidence interval is for the mean difference...you're 95% confident that the mean difference is in that interval. The way R calculates the MEAN DIFFERENCE depends on the order of entry of the variables. (ie) t.test(Before, After) will return a mean difference using DIFF=Before-After and t.test(After, Before) will return a mean difference using DIFF=After-Before. So, the sign of the difference may change. If the after scores are better on average, then t.test(Before, After) will return a negative mean difference as DIFF=Before-After will result in more negative values. So my guess is that it is likely that. try changing the order you entered the two variables, and you will see the sign of the mean difference change (the summaries will just change sign, but the numeric values will remain the same)

  • @gonzaloignazi4423
    @gonzaloignazi4423 5 лет назад

    Great tutorial. I have trouble running t.test. An error message appears saying "object (variable" not found, and my is contained in a table like the one in the video. When I use the command Head () it shows me the data correctly. Anyone knows what the issue could be? thanks!

    • @marinstatlectures
      @marinstatlectures  5 лет назад +2

      you either need to to specify where the variables are, eg *t.test(data.name$**variable1.name** ~ data.name$variable2.name)* or you must first attach the data using *attach(data.name)* , and then you can call on variables by name *t.test(**variable1.name** ~variable2.name)*

    • @gonzaloignazi4423
      @gonzaloignazi4423 5 лет назад +1

      @@marinstatlectures Thank you very much! now it works.

  • @Lyn-eg3id
    @Lyn-eg3id 10 лет назад

    Hi Again.
    Is there a reason why the output doesn't show the standard deviation and standard error? What does it mean to get a negative value for the t statistic in the print out?

    • @marinstatlectures
      @marinstatlectures  10 лет назад

      Hi Lynette 3132 , it doesn't return the SD or SE as they are not really relevant to look at. you can have R calculate them if you like though. a negative test statistic means that the mean of the second group is larger than the mean of the first group. (eg) you use the command *t.test(group1, group2, paired=T)*. the numerator of the test statistic is (mean1 - mean2), so the negative test statistic is telling you that the mean for the second group is larger than the mean of the first group. the p-value and/or confidence interval can help you decide if they are statistically significantly different.

    • @Lyn-eg3id
      @Lyn-eg3id 10 лет назад +1

      Thank you! I love your videos.

  • @Pochiko2008
    @Pochiko2008 2 года назад

    Brilliant. Thanks so much

  • @oacho3
    @oacho3 8 лет назад

    Hi Mike, I became a devoted follower of your video by now and i greatly appreciate your support. I was wondering, let say i have to repeat the exact same experiment that you use here on 9 different species of animals. To test if the "before" and the "after" conditions are significantly different from 0 in each species, do I run 9 separate paired t tests? Thanks!

    • @marinstatlectures
      @marinstatlectures  8 лет назад

      Hi +oacho3 , thanks. and yes, that sounds like a good simple approach to testing that. you may want to correct for multiple comparisons...using something like Bonferroni's correction for Multiple Testing. basically, the adjustment consists of using an alpha of 0.05/9 = 0.00555 for each of the tests, to have overall alpha=Type I error rate of 5%. similarly, this would mean to use 99.444% confidence for each confidence interval, to have 95% confidence over all 9 confidence intervals simultaneously. there are other corrections that can be done, but this one is the simplest.
      the reason for doing this 'correction' is that with each test/confidence interval, the change of a Type I error (falsely rejecting Ho) increases. this is a way to control the Type I error rate over all tests so that it does not inflate. there are, of course, drawbacks to using an adjustment like this.

    • @oacho3
      @oacho3 8 лет назад

      +MarinStatsLectures Thank you so much for a great and clear answer! I love your videos. The contents are perfectly paced and focused, flow like a charm, not too complex nor too basics. Is there some way i could show my gratitude on top of telling all my friend about your channel? May I send you a cake from Italy? A bottle of wine?

    • @marinstatlectures
      @marinstatlectures  8 лет назад

      Thanks oacho3 , we appreciate the sentiment! and while we do love a good bottle of Italian wine, that's not necessary. but thanks very much for the offer ;)

  • @marcelas7928
    @marcelas7928 10 лет назад

    Hi Mike, I am trying to conduct a Paired T test but my R doesn't run it.
    I wrote this:
    > t.test (beforeD,afterD,mu=0,alt="two.sided",paired= T,conf.level=0.95)
    and then appears this legend:
    Error en t.test.default(beforeD, afterD, mu = 0, alt = "two.sided", paired = T, :
    data are essentially constant
    if I conduct the same but paired=F....runs it perfectly but I want paired t test.
    Do you know what is wrong with this?
    Thank you . Marcela

    • @marinstatlectures
      @marinstatlectures  10 лет назад

      Hi Marcela S , its tough to tell from a distance, but saying that the data are constant suggests that the change from before to after for each pair is the same...so there is no estimate of variability...each difference is the same (or constant). thats what it sounds like to me...

    • @marcelas7928
      @marcelas7928 10 лет назад

      MarinStatsLectures ok Thank you, I will check the data maybe is something wrong...tks.

  • @rockstarvarun1995
    @rockstarvarun1995 7 лет назад

    Mike why didn't we do ....t.test (before~ after) ......in this video...I am getting error for same :(

    • @panagiotisgoulas8539
      @panagiotisgoulas8539 6 лет назад

      cause you don't compare categories of a categorical variable unlike before where you checked elements of SAME column

  • @miffypurslow
    @miffypurslow 3 года назад

    This does not work and no matter what I do there is an error every single time.