## Calculate the P-Value in Statistics - Formula to Find the P-Value in Hypothesis Testing

hello welcome to this lesson and

mastering statistics we're going to

continue working with hypothesis testing

in this particular case we're going to

start to talk about the concept of a

p-value so keep in mind that this right

for now is in the context of our large

sample hypothesis testing of means so

we're doing hypothesis testing with

means we're doing large samples for

right now and so we have sample size is

greater than 30 now up until now we've

been doing everything in terms of

rejection regions all right and that's

basically where the level of

significance alpha whether it's left

tail right tail or to tail you have to

set it all up but essentially you create

these boundaries and these are rigid

boundaries that you can then look at

calculate your test statistic from your

data see where it falls and depending on

where it falls you can tell if you have

rejected the null hypothesis or if you

fail to reject it all right well every

once in a while when I do teaching I get

around to a topic that I get really

excited about because p-values in this

case is something that gives a lot of

students a lot of heartburn a lot of you

figure out what it really means well I'm

excited because I can explain this to

you I think with some concrete examples

and especially after we get through this

we do a couple more examples

hopefully I believe that you will have

very very good understanding what

p-values are intuitively number one

thing before you do any kind of you know

diving into this is I want you to keep

in the back your mind that's the purpose

of a p-value really the process and sort

of the reason that we do it is really no

different than what we've been doing

before essentially we want to figure out

Lin which reject that null hypothesis

and when we fail to reject it so before

we we were using the rejection regions

and figuring out where it falls here

we're doing something very similar at

first it's going to look totally

different but then when I start talking

about it enough you'll realize it's

exactly the same thing so keep that in

back your mind we're using it for the

same purpose so we just go down my list

make sure I say everything rejection

regions work perfectly fine and

statistics there's nothing wrong with

rejection region but p-values are more

common to real research so if you read a

real research paper in statistics they

do a big study they figure out what the

hypothesis is and reject a null

hypothesis you're going to see p-values

running around there their explanation

so it's much much more calm and I'll

explain why it's more common in real

research and so that's why we learn it

here and I've already said this once

I'll repeat it again p-values are just

another trigger to decide when we should

reject that null hypothesis and when we

should fail to reject it first I need to

write down a definition of what you're

going to see in a book what a p-value is

so let me get that down for you but just

keep in mind don't worry too much about

the definition as we write it down I

mean I'll kind of explain it but as we

go through it you'll get a much more

intuitive understanding of what a

p-value is that will be much more

concrete than what I'm going to write

down here the following is what you'll

typically see in a book it will say

p-values and a book will typically

define it as follows this is a good

definition there's nothing wrong with it

it's just I need to show you some

pictures for you to really understand it

it's basically the probability and by

the way that's called a p-value because

it's basically P for probability of

obtaining of obtaining a sample I'm

going to put in quotes here because I

need to explain it more extreme then

then the ones observed in your data

assuming

that the null hypothesis is true the

crucial part of what we're reading here

is that the concept of a p-value is just

a probability and you know what

probability has been talking about that

for ages in the class probability right

it's a decimal between 0 and 1 the

probability of obtaining a sample more

extreme than the ones observed in your

data now what do I mean by observed in

your data it's because all of these

hypothesis tests involve you know you

write down your null hypothesis you

write down your alternate and then you

go get some data because you need to try

to you know just prove the null

hypothesis or reject it or whatever so

you last 23 or 28 or 99 people what they

had for breakfast that morning or

whatever that's the data so you collect

that data that sample data that you have

whether it's 50 samples or 60 samples

that's your sample data and you have all

of those different values they're

typically you're looking at a mean in

this case we've been talking about

hypothesis testing of means so you're

looking at the length of pencils on an

assembly line volume of water being

filled into you know the bottles of

water in a factory or something you're

talking about numbers and the hypothesis

test that we've been doing so far have

been all about the mean values of those

things so we go and select some to study

and sample to try to test that alternate

research hypothesis and we get the

values back the p-value is the

probability of obtaining a sample more

extreme than the ones observed in your

data so you have a collection of data

that you get from the assembly line or

whatever the 25 samples are the 50

samples that you have that's the data

that I've collected the p-value is

giving a representation of what would be

the likelihood of getting a data even

more extreme than the one that I

actually did collect and the reason I

put more extreme imporant in quotations

here is because it kind of depends on

the problem that you're doing as to as

to which way is more what more extreme

actually means in other words if I'm

doing a right tailed test right tailed

be that way then basically I'm measuring

the length of pencils and I spend my

research hypothesis is that the pencils

are greater than 3 meters long right so

more my data more extreme is going to be

in there in the right hand direction

more extreme towards that tail but if

I'm doing a left tailed test then more

extreme means more direct more

strain in the left-hand direction I

think a lot of this can be simplified by

writing some of this down so let's say

that I have a left-tail test right very

common thing that we do in statistics

left-tail test so let's draw a picture

of it real quick so we have what we have

is a little distribution like this this

is a V distribution or a normal

distribution centered at zero okay so

what it's basically saying is if I'm

doing a left tailed test don't forget

what I'm really doing let me switch over

to red here on the left tailed test

there's always a little region here off

to the left right that we shade right

now typically in previous problems this

shaded region has always been the level

of significance right that's that's what

I always told you your level of

significant goes goes in your tail and

wherever it lands and you draw your

conclusion here we're doing things a

little bit different I'm just explaining

what a p-value is to you if you're doing

a left tailed test and by definition the

null hypothesis is here and we suspect

that the candy bars in this case but the

left tail tests are shorter than they

should be in other words we think

they're getting smaller then the null

hypothesis said so we're moving this way

okay now when we do the sampling and we

get all the values of the candy bars we

calculate a test statistic that's this

number right that's what we've been

always been testing based on the sample

mean hypothesis mean and the standard

deviation of the sample and the number

of samples we get a test statistic here

so I'm going to put that Z down here and

this is what we get from our sample data

this value of Z comes from the sample

data right so it's kind of a

representative of this value of these

kind of like a representative indication

of what the sample data really is

telling you it's taking into account the

mean the standard deviation the number

of samples so that's what this kind of

means this whole time we've been

comparing this number to the level of

significance basically and where that

falls on the chart to figure out if we

reject the null hypothesis or not so

about testing it right now the concept

of a p-value is basically this value of

Z comes from the test statistic it is

the test statistic and it represents

so when we say the p-value is a

probability of obtaining a sample more

extreme than the ones observed in your

data what I'm basically saying is that

this value of Z is called the test

statistic and this comes from my sample

data so all of these values here to the

left all of the Z values to the left

these are more extreme all of these

possible values of Z to the left are

more extreme than this one and the

reason I'm counting to the left is being

more extremist because this is a left

tailed test right so the bottom line is

the p-value is well geez we just switch

over to green the p-value is this area

that's shaded right here right it is the

probability remember probabilities are

areas under a curve of obtaining a

sample more extreme than the ones

observed in your data my data gives me a

sample standard deviation of sample I'm

sorry a sample mean a sample standard

deviation in the number of samples

here's what we're relating to the

hypothesis the null hypothesis we get a

z value back this represents my set of

data I'm saying that it falls right here

I'm not doing any testing yet I'm not

testing any null hypothesis saying the

data that I get back it's kind of

represented in the chart here it's far

enough away from the null hypothesis to

the left we're doing a left tailed test

there you go data points more extreme

than the ones that I've actually

collected or by definition to the left

and the area of all of those possible

data points that I could get to the left

is what we call the p-value right more

extreme means to the left in this case

now let me go over here and we'll do now

a right tailed test and hopefully you

kind of have an idea of what it's going

to be before we actually do it but let

me go ahead and do it just to be

absolutely explicit in a right tailed

test we have a distribution same as we

do before which is always by the way

centered at zero

member dot and these are no these are

normal distributions because we have

large sample sizes right so I collect my

data let's say I'm doing a right-tailed

test and I have you know candy bars

coming off an assembly line my research

hypothesis says these candy bars are

longer than 10 centimeters that's the

research the alternate hypothesis so

longer than 10 centimeters that would be

a right hand symbol so I would be doing

a right hand I'd be doing a right hand

till a right tailed test okay so I would

collect all that I would go and look at

35 candy bars off the assembly line

and I would get information from that I

would get a sample mean I would get a

sample standard deviation and I know how

many samples that I collected this is

the hypothesis means the null hypothesis

mean I would calculate this number and I

would get a value of Z this value of Z

is kind of a represented it's like one

number that generally represents the

entire set of data that I collected it's

one number right so this value Z goes

here all right and what I'm basically

saying is that all of these values to

the right or more extreme than my data

right and a p-value is the probability

of obtaining a sample more extreme than

your data set so my data set returns a

value of Z here everything to the right

we're saying is more extreme because

it's a right tailed test right and the

probability of getting something more

extreme than my data set that I had here

is what we call the p-value so it's

literally the area under the curve to

the right of the test statistic Z that

you calculate for your data in this case

over here it's the area to the left of

the test statistic that we calculate for

our data so I know because I'm using red

the tails some of you guys are thinking

that this is the level of significance

it's not the level of significance all

I've said is that I calculate the test

statistic from my sample data it's

representative of the data that I

you know have measured I put it on this

guy and then more extreme to the right

for a right-tail test is called a

p-value so it's the area to the right

more extreme to the left is going to be

in that case for a left tailed test

that's why I put more extreme than

quotation now there's one more case I

want to show you or in fact actually

before we get to that let me go and give

a little bit more concrete examples of

left and right tailed testing okay

let's say as a actual example that the

null hypothesis is that the mean is

greater than equal 0.15 and the

alternate hypothesis is that the mean is

less than 0.15 so this is a typical

problem that you could actually have the

alternate hypothesis is to the left so

you know you're doing a left-tail test

that tells you that all right also given

to you in the problem you're given that

from the data the test statistic Z is

negative one point three four this

doesn't fall out of thin air what this

basically is is you collect all of the

lengths or the volumes or whatever

here's your measuring and you dump that

information the sample mean sample

standard deviations in the number of

samples you stick it into the test

statistic and out comes a value of Z

that number of Z that that value of Z is

representative of the data set that you

have it kind of takes into account all

the data points the spread of the data

and everything and out comes one number

that's kind of representative of that

whole data set that's what we've been

using it for all along we've been using

that one representative number to tell

us if we're in the rejection region or

not okay so that is all given to us we

haven't done anything yet but we know

we're doing a left tailed test so if I

were to draw this I would draw something

like this and I know that I'm doing a

left tailed test okay so the bottom line

is the value of Z that comes about from

the sample data negative one point three

four and since I'm doing a left tailed

test I come up here and I shade this guy

to the left because I'm getting the

probability of getting a sample more

extreme than the data that I actually

collected so

this area here is called the p-value all

right now how do we actually find the

p-value we haven't actually calculated

anything yet how we actually find it

well this is a normal distribution you

have a chart of the normal distribution

in the back of your textbook every

statistics textbook does

don't forget the normal distribution

gives you the area to the left it's

different than the T distribution which

gives you the area to the right I know

it gets a little bit confusing you

always have to remember that the table

for a normal distribution is giving you

the area to the left so what if what do

we do if we want to find this p-value

well we have the value of Z and it has

the area shaded to the left of Z so all

we literally have to do is go to the

table right and find the probability

that Z is less than negative one point

three four so literally all we do is

look at z- 1.34 in our Z distribution

table the area that it gives us is the

area to the left which is exactly what

we want and I get zero point zero nine

zero one so that means the p-value zero

point zero nine zero one that is the

p-value for this problem so if you were

given a situation where somebody says

here's the null hypothesis here's the

alternate hypothesis here's the z-score

that comes from the sample data

calculate the p-value for this problem

now notice we haven't done any

hypothesis testing yet I haven't even

gotten to that yet but I just want you

to get practice with finding the p-value

well the only reason you need this is to

know that it's a left tailed test this

is representative of our sample data so

we plop it on the chart and since it's a

left tailed test the probability of

getting a value more extreme than our

sample data would be the probability of

to the left of this value of z which I

can readily look up in the back of any

book so that's how you find a p-value

for a left-tail test right now what

happens if we have a right-tail test

okay what happens if we have a right

tailed test

well for a right tailed test

okay for a right-tail test let's pretend

that we have a null hypothesis which as

a mean of less than or equal to zero

point four three and an alternate

hypothesis looks to put an A there a

mean greater than zero point four three

and let's say from the data Z is equal

to two point seven eight so all we have

is this and the question is what is the

p-value for this problem notice we don't

have a hypothesis we have some

hypothesis on the board but we haven't

been asked to test it we haven't really

been given a level of significance we

haven't really been told exactly

everything about the problem all I want

you to do for this problem is find out

what is the p-value well you have to

know what a p-value is it's the

probability of getting a value more

extreme than the sample data that you

collected now we don't have the raw data

but we have the Z value the test

statistic that came from that guy there

so let's go and draw a picture and get

our bearings for what we actually have

and what we actually need so here is our

distribution this is a Z or a normal

distribution and notice that this is a

right tailed test this is a right tailed

test so zero goes in the center and this

value of z that I got from my data was

two point seven eight right that is a

representative number in terms of Z that

kind of represents the whole data set

that I've collected we put it on the

curve right there what will be the

probability of getting a value of next

time we select a sample or whatever of

being more extreme than that well this

is a normal distribution so we go up

here we shade to the right more extreme

in this case means to the right because

it's a right tailed test more extreme in

the previous case

was to the left because it's a left-tail

test so the phrase more extreme really

depends on the kind of problem that

you're dealing with that's why I put it

in quotation marks so what I'm looking

for is the probability that I've select

my next sample and I get a value more

extreme than the data set that I

previously collected so that means that

this area here is going to be the

p-value the area under the curve to the

right of this value of Z so in order to

do that you can use your normal

distribution table in the back your book

the probability of getting a value of Z

greater than 2.7 aims when I'm after but

remember that when you're using a normal

distribution you can't just put the

number 2.78 in there and circle the

answer because what we're looking for is

the area to the right right but if I

actually put 2.78 n into the normal

distribution it's going to give me the

area to the left in other words it's

going to return the area of everything

over here so if you remember back to the

very beginning of mastering statistics

like the very first volume when we start

basically said when you're using that

table if you want the area to the right

the way you actually handle it is you

basically say that's going to be equal

to the probability of Z you flip the

sign around negative two point seven

eight because remember everything

symmetrical this is two point seven

eight here I'm interested in this area

of the area the only thing I care about

if I look on this side right around here

Z is negative two point seven eighty and

the area to the left of that negative

value of Z is going to be exactly the

same as the area that I care about here

so when I'm trying to find areas to the

right with a normal distribution

I flip the sign around the the

inequality round and I change the sign

of Z there so I go into my chart and I

look up the value of negative two point

seven eight in my chart which is

somewhere over here it's going to return

an area to the left that area is the

same as what I care about so whenever I

do that I'm going to get zero point zero

zero to seven so all you have to do is

say that that is the p value zero point

zero zero

two 7s the p-value the p-value literally

is the probability of obtaining a value

like the next sample I were to take the

probability of obtaining a value more

extreme than the data set that I've

collected the data set that I've

collected is represented mathematically

by this test statistic it contains kind

of all the raw information and boils

down to a to a value of Z so that's what

a p-value is I keep saying it over and

over again I want you to visualize that

the p-value is an area to the right or

it's an area to the left and when we get

into situations where it's a two-tailed

test it's going to be very similar and

I'll get to that whenever I get to that

but for right now I want you to

understand the concept of a p-value

notice we haven't done any actual

hypothesis testing it I haven't even

told you how to use p-values to make

decisions right but I told you at the

beginning that the big overall arching

concept here is that p-values are going

to be used to tell us if we reject or

fail to reject the null hypothesis just

like the rejection regions we did before

I promise you that we are going to get

there you are going to understand but

you have to take it kind of baby steps

with me first understand what the

p-value is it is the area to the right

of the value of Z that you get from your

test that you get from your sample data

if it's a right tailed test or to the

left if it's a left tailed test

all right make sure you understand it so

we've done two problems we've calculated

the p-value for one four right one for a

left I want to stop here go on to the

next section where I'm going to show you

how to use what these p-values are in

order to make decision in other words to

tell us if we reject or fail to reject a

hypothesis