< Return to Video

Hypothesis Testing for Means

  • 0:02 - 0:04
    Hi. In this video we are going to continue
  • 0:04 - 0:06
    to talk about inference.
  • 0:06 - 0:09
    But now we're going to be talking about
    how you can conduct hypothesis
  • 0:09 - 0:12
    tests in R.
  • 0:12 - 0:16
    So the general hypothesis
    testing procedure
  • 0:16 - 0:20
    is we always state hypotheses
    about your parameter.
  • 0:20 - 0:23
    We collect some data.
  • 0:24 - 0:27
    We construct a test statistic.
  • 0:29 - 0:34
    We then apply a decision
    rule so we can either
  • 0:35 - 0:38
    do that through a critical value
  • 0:38 - 0:41
    or with p-values or like a
    critical region, excuse me.
  • 0:41 - 0:44
    Or with p-values.
  • 0:44 - 0:46
    And then we will draw
  • 0:46 - 0:49
    conclusions in context.
  • 0:49 - 0:53
    So the first research question
    we're going to talk about
  • 0:53 - 0:57
    today is we're going to continue
    using the idea of iris flowers.
  • 0:57 - 0:59
    And see like we're interested in one.
  • 0:59 - 1:04
    And try to hypothesize
    that we think that the average
  • 1:04 - 1:07
    petal length for iris flowers
  • 1:08 - 1:11
    is four centimeters. So,
  • 1:13 - 1:16
    our null hypothesis would be
  • 1:17 - 1:20
    that average,
  • 1:20 - 1:23
    petal length is equal to four centimeters.
  • 1:23 - 1:27
    And our alternative will be average
  • 1:27 - 1:31
    petal length is not equal
    to four centimeters.
  • 1:32 - 1:34
    Okay.
  • 1:34 - 1:36
    The data we are going to use
  • 1:36 - 1:39
    is the iris petal length data.
  • 1:39 - 1:41
    So it's from the iris dataset.
  • 1:41 - 1:44
    And this is the petal length and variable.
  • 1:44 - 1:47
    Just to kind of remind us, it is just 150
  • 1:47 - 1:50
    observations of different irises.
  • 1:52 - 1:55
    To construct our test statistic
  • 1:55 - 1:59
    we will first need an xbar value,
  • 2:00 - 2:02
    which we can find by taking
  • 2:02 - 2:05
    the mean of our sample.
  • 2:06 - 2:09
    So the mean of the iris of petal length.
  • 2:12 - 2:15
    Which will be 3.758.
  • 2:15 - 2:19
    We also are going to need
    the hypothesized value
  • 2:19 - 2:24
    that we are wanting to hypothesize,
    which is four centimeters.
  • 2:24 - 2:29
    So I'm going to just call that mu
    because that's the parameter of interest.
  • 2:29 - 2:31
    We're going to say it's equal to four.
  • 2:32 - 2:33
    We also need to know
  • 2:33 - 2:37
    the sample standard deviation, s.
  • 2:37 - 2:40
    And so you can get that by
    doing this standard deviation
  • 2:40 - 2:43
    of the variable.
  • 2:44 - 2:47
    That value is 1.765.
  • 2:47 - 2:50
    And then we also need to know
    the number of observations.
  • 2:50 - 2:53
    So, n. So we will reduce
    the length function.
  • 2:53 - 2:57
    And then I'll count how many
    observations are in your data set
  • 2:57 - 3:00
    which is 50.
  • 3:00 - 3:02
    Now once we have all of those
  • 3:02 - 3:06
    individual pieces we can
    build the test statistic.
  • 3:06 - 3:11
    Since we are doing a hypothesis test
    for a mean, we will be constructing
  • 3:11 - 3:16
    what is known as like a t, a
    test statistic for a t-distribution.
  • 3:17 - 3:20
    So I'm going to call it t-test stat.
  • 3:21 - 3:23
    And how we create
  • 3:23 - 3:27
    that is we do xbar minus
    mu in the numerator
  • 3:27 - 3:32
    divided by I'm just gonna
    put this in parentheses
  • 3:32 - 3:37
    as well. S divided by
    the square root of n.
  • 3:38 - 3:41
    So thankfully we have all of these pieces
    already xbar, mu,
  • 3:41 - 3:45
    s, and n. S, n, and xbar
    all come from the data.
  • 3:45 - 3:49
    Mu is the value we specified
    in our null hypothesis.
  • 3:49 - 3:53
    And this will compute
    our test statistic for us,
  • 3:54 - 3:55
    which is
  • 3:55 - 4:01
    -1.67897. So.
  • 4:06 - 4:07
    Here we go.
  • 4:07 - 4:09
    So our next step
  • 4:09 - 4:12
    is to apply a decision rule.
  • 4:16 - 4:19
    So we have two different
    ways we can do that. We'll-
  • 4:20 - 4:22
    We will use a significance level
  • 4:22 - 4:25
    or an alpha of 0.05.
  • 4:25 - 4:28
    So I'm just going to go
    ahead and set that.
  • 4:32 - 4:33
    And then if we want to
  • 4:33 - 4:36
    calculate a rejection region,
  • 4:36 - 4:39
    because there's two different
    kinds of decision rules we can do.
  • 4:39 - 4:40
    Rejection region.
  • 4:40 - 4:43
    We can find which critical value
  • 4:43 - 4:47
    will give us a tail probability of 0.0 uh-
  • 4:48 - 4:51
    Or since we're doing a
    two sided hypothesis test,
  • 4:51 - 4:54
    we'll do our alpha divided by two.
  • 4:54 - 4:55
    I'll kind of show you.
  • 4:55 - 4:58
    So our rejection region
  • 4:59 - 5:02
    is we're going to try, we're
    going to find the critical value
  • 5:02 - 5:07
    that, fits the t-distribution,
    where the probability in the tail
  • 5:09 - 5:11
    is equal to alpha over two.
  • 5:11 - 5:15
    Because we're doing a two
    sided interval hypothesis test.
  • 5:16 - 5:20
    Our degrees of freedom is needed
    for the t-test, which is n minus one.
  • 5:21 - 5:27
    And since we are, our test
    statistic with a negative value,
  • 5:27 - 5:31
    meaning that it's on the left side of the,
  • 5:31 - 5:34
    of the mean on the curve,
  • 5:34 - 5:38
    we will go ahead and say
    lower.tail equals true.
  • 5:38 - 5:43
    Because we want the lower tailed like
    or the smaller the tail end probability.
  • 5:43 - 5:48
    If this is a positive number 1.67
    we would then do lower.tail
  • 5:48 - 5:52
    equals false because we
    want the upper tail.
  • 5:53 - 5:56
    We want kind of the extremes.
  • 5:56 - 6:00
    So anything from where our test
    statistic is and more extreme.
  • 6:01 - 6:03
    So what this will tell us
  • 6:03 - 6:06
    is our, oh, alpha not found.
  • 6:06 - 6:09
    I forgot to run that line. There we go.
  • 6:11 - 6:11
    Okay.
  • 6:11 - 6:17
    So our rejection value is one, -1.976.
  • 6:18 - 6:22
    So what this is telling us
    is that if our test statistic
  • 6:22 - 6:27
    is equal to -1.976 or less,
  • 6:27 - 6:33
    or if it's greater than positive 1.976,
  • 6:33 - 6:36
    then we will reject our null hypothesis.
  • 6:39 - 6:43
    And in this case, since our test
  • 6:43 - 6:48
    statistic is not in the extreme, it's
    actually greater than this value,
  • 6:49 - 6:52
    we will fail to reject
    our null hypothesis.
  • 6:52 - 6:55
    So this is telling us that,
  • 6:56 - 6:57
    we will fail to reject
  • 6:57 - 7:01
    our null, meaning that we do not
    have enough evidence to conclude
  • 7:01 - 7:05
    that the average petal length
    is not equal to four centimeters.
  • 7:06 - 7:10
    The other way you can apply a
    decision rule is with a p-value.
  • 7:11 - 7:13
    And since we are doing a
  • 7:13 - 7:15
    two sided hypothesis test,
  • 7:15 - 7:19
    we will, can do two times
    whatever probability
  • 7:19 - 7:22
    we get because we're going
    to be calculating it for one tail.
  • 7:22 - 7:25
    But since we're doing two sided
    we'll just need to multiply it
  • 7:26 - 7:27
    by two.
  • 7:27 - 7:30
    And so what we're going to put
    in here is we're going to put
  • 7:30 - 7:34
    in our test statistic that we get.
  • 7:35 - 7:38
    The degrees of freedom again
  • 7:38 - 7:40
    and again we're going to do lower.tail
  • 7:40 - 7:44
    equals true because our
    original test statistic is negative.
  • 7:44 - 7:48
    So we want a lower tail
    like the extreme value.
  • 7:49 - 7:53
    And then we're going to multiply by two
    again because we are doing a two sided
  • 7:54 - 7:57
    p-va- two sided hypothesis test.
  • 7:57 - 8:00
    And then this is the value
    that we compare to
  • 8:00 - 8:03
    our alpha, which is 0.05.
  • 8:03 - 8:06
    So if our p-value is less than the alpha
  • 8:07 - 8:11
    less than 0.05, we would
    reject the null hypothesis.
  • 8:11 - 8:14
    In this case our p-value
    is greater than 0.05.
  • 8:15 - 8:18
    So we would fail to reject our null
    hypothesis again as well.
  • 8:19 - 8:22
    You should get the same conclusion.
  • 8:23 - 8:26
    With either method, you should be
  • 8:26 - 8:29
    coming to the same
    reject or fail to reject.
  • 8:29 - 8:32
    You should not be getting
    different conclusions.
  • 8:35 - 8:36
    So that's how you can kind of
  • 8:36 - 8:39
    compute a hypothesis test by hand.
  • 8:40 - 8:44
    But as always, usually in R
    there is an easier way to do it.
  • 8:44 - 8:47
    So there is a function t.test
  • 8:47 - 8:50
    which may be familiar from when we did.
  • 8:50 - 8:52
    Confidence intervals for means.
  • 8:52 - 8:54
    And this is actually you can
  • 8:54 - 8:57
    do confidence intervals plus
    hypothesis testing in here.
  • 8:58 - 9:01
    So we still are going to
    have the same null.
  • 9:01 - 9:04
    And I turned it off
    hypotheses from up here.
  • 9:05 - 9:08
    And so what we're going to do
    is we're going to just say t.test,
  • 9:09 - 9:12
    give it the data that we
    are doing the t-test on,
  • 9:13 - 9:16
    which is the petal length of iris flowers.
  • 9:17 - 9:20
    We need to specify what our
  • 9:20 - 9:23
    null hypothesis new value is.
  • 9:23 - 9:27
    We're saying that we are
    hypothesizing that the true, average
  • 9:27 - 9:29
    petal length is four.
  • 9:29 - 9:32
    So we will say mu is equal to four.
  • 9:33 - 9:36
    And then we also need to specify that our,
  • 9:36 - 9:39
    our, that our alternative hypothesis is a
  • 9:40 - 9:43
    two sided hypothesis test.
  • 9:43 - 9:46
    Okay.
  • 9:46 - 9:48
    And if we go ahead and run that.
  • 9:48 - 9:52
    And notice it shows it is a one
    sample t-test which is perfect.
  • 9:52 - 9:54
    We have one sample and a t-test.
  • 9:54 - 9:58
    It gives us a t which
    is our test statistic
  • 9:58 - 10:01
    which should match what we got up here.
  • 10:01 - 10:03
    And it does.
  • 10:03 - 10:05
    The degrees freedom is pretty easy.
  • 10:05 - 10:08
    150 minus one. And then here's a p-value
  • 10:08 - 10:11
    Same exact p-value we got
    here by doing a by hand.
  • 10:13 - 10:14
    And then
  • 10:14 - 10:17
    you can kind of see
    they have xbar right here.
  • 10:17 - 10:21
    And then it also gives you
    that 95% confidence interval.
  • 10:22 - 10:24
    So this is an, quick and easy way
  • 10:24 - 10:27
    that you can compute a t-test for me.
  • 10:29 - 10:32
    You can this is kind of showing
    you how to do it all by hand.
  • 10:32 - 10:35
    And then this will show you kind of
    how to just do it in one simple step
  • 10:35 - 10:38
    by computing a p-value for you.
  • 10:39 - 10:42
    If you wanted to change what your,
  • 10:42 - 10:44
    your null hypothesis was.
  • 10:44 - 10:48
    So say, like you were testing, is
    the mean equal to two instead?
  • 10:49 - 10:50
    You could totally do that.
  • 10:50 - 10:55
    And then you can see that
    this p-value is way, way smaller.
  • 10:56 - 10:59
    Or if you wanted to
    change your alternative.
  • 11:00 - 11:04
    So it's not that it's just not
    equal to four and it's, you know,
  • 11:04 - 11:07
    maybe less or greater than. So
  • 11:08 - 11:10
    you could do it like this.
  • 11:10 - 11:12
    You can do less or
  • 11:13 - 11:16
    greater and that'll tell you,
  • 11:18 - 11:19
    which, that'll
  • 11:19 - 11:23
    change the output of your hypothesis test,
  • 11:23 - 11:26
    kind of depending on if you're
    doing a one sided or two sided test.
Title:
Hypothesis Testing for Means
Video Language:
English
Duration:
11:29
Utah_State_University edited English subtitles for Hypothesis Testing for Means
Utah_State_University edited English subtitles for Hypothesis Testing for Means
Utah_State_University edited English subtitles for Hypothesis Testing for Means

English subtitles

Revisions Compare revisions