Welcome back to practical time series analysis.
In these introductory lectures,
we're reviewing basic statistics.
In this lecture in particular,
we'll look at some inferential statistics.
Now if your statistical background is strong,
and if you're very comfortable in the R environment,
you can move through these lectures very quickly.
They're really meant for people who either haven't done
statistics in any meaningful way in quite some time,
or who are just new to R. Our objectives.
We do say this is basic inferential statistics.
Our objectives are to review some basics.
Learn how to develop graphical intuition in new data set,
based upon the commands available in R.
And learn how to perform a simple hypothesis test.
The data set we'll be using is a famous traditional data set.
It's the Gossett Data on sleep.
So, he's reporting on results that other researchers actually had already published,
and using it to develop his techniques.
But the basic data set looks at two soporific drugs,
these are drugs meant to induce extra sleep in a patient.
And there are 10 people in play in this data set.
There are two drugs and we're looking at the increase over
control for each of these 10 individuals with each drug.
The formative data frame is 20 observations and we have three variables here.
So, 20 observations, these are 10 people,
and so we're looking at the effect of each of two drugs here.
So we've got extra group and ID.
Extra is going to be the extra amount of sleep.
Group will tell you which drug is in play,
and ID tells you which patient.
Of course, always plot your data.
The plot command is a rather powerful one,
and it will make decisions based upon the kind of data
you're presenting it as to what kind of plot it's going to return.
We're going to plot the extra sleep on group.
So, think of that as drug and main of course is going to put a title on a graph.
We'll look at extra sleep in Gossett Data by group.
Now, after that we'll do a couple other things.
I want to have the data available to me very easily in a variable.
So, I'm gonna say extra dot one,
is the extra sleep for those in group one.
So we're testing group identically equal to one or group identically equal to two,
as we assign our numbers to each of these two vectors.
When we look at the graph,
we've got extra sleep.
it looks like the second group,
the second drug has a pretty clear advantage over the first.
I don't see a huge difference in heterogeneity here, there is some,
but I think what's most pronounced in this graph is that,
now this bar here in a box plot of course is telling you the median not the mean,
but the median certainly seems to be higher in the second group.
Now that's a visual impression,
and what we'll do now is try to follow it up with a standard statistical test.
As we test our hypothesis,
we'll use the command t. test,
we'll put in extra one and extra two as our data.
You can do tests,
you'll recall from elementary stats with independent samples,
and there are different ways to go within
independent samples depending upon your variability.
Right now instead, we're going to treat these data as
paired because remember there are only 10 people in the study,
and there are two different drugs.
We're going to do a two sided test rather than a one sided test,
because coming in I had no theory,
no intuition that one drug would be better than the other.
Our results look like this.
We'll obtain a t value of negative four or so.
That's a fairly hefty t value.
Now, if that were a z value from a normal distribution,
it would be quite quite large.
How large it is with a T distribution,
depends upon your sample size.
Our degrees of freedom in a pair of T-test like this with
ten individuals remember is nine and minus one,
and the p value we obtain is less than the standard nickel.
Less than point zero five.
It's even less than point zero one.
And I think many people would say that these data are highly significant.
R agrees and is going to go with
the Alternative hypothesis that the there is a difference between the two drugs.
It's also good to report a confidence interval.
And another approach to a test like this would be to calculate a confidence interval and
see if it includes zero as a plausible value. It does not.
So, the 95 percent confidence interval
here is between around negative two and a half to a negative point seven.
Now, if it's been a little while since you've done
a confidence interval or a hypothesis test,
let's go back and remember what this is all about.
In a standard hypothesis test we have a null hypothesis and an alternative hypothesis,
traditionally labeled H sub zero, and H sub one.
The null hypothesis will be no difference,
just that the mean response is going to be the same for both drugs.
The alternative since we're doing two tail tests will be that it's not the same.
Alpha is what people,
or researchers often set up before they conduct the tests,
probability of a type one error.
The probability that we're going to reject a true null hypothesis is
fairly standard to say that alpha equal to
the two values point zero five or point zero one.
The t value that we calculated here,
is we're going to look at the average of
the differences which is the same
if you follow the language as the difference of the averages.
So, we're looking at the bar here.
Essentially, we're just taking the average,
the mean value with the first group,
and subtracting off the average on the second.
It's a very intuitive thing to do.
We'll compare that to our null hypothesis value of zero.
Downstairs we're going to look at variability.
So, we're looking at the variability of the averages here not of individuals.
We're going to take s sub d. So,
this is the sample standard deviation of the differences.
Now, be careful, if you take
the differences for these 10 individuals between the two drugs,
take their response on the first drug and subtract off the response in the second,
and do that for all 10,
and then take the standard deviation of that,
that's the standard deviation of the differences.
That's not going to be the same number generally speaking,
as if you take the standard deviation of the first data set,
and subtract off the standard deviation of the second.
We just have to be a little bit careful here.
But the standard test is to look at the standard error down here,
standard deviation divided by the square of N,
to give us a measure of variability.
And that's how we calculate,
you can follow through the numbers,
negative for t value.
So as we just said,
d bar is the average of the differences,
or the difference of the averages however you like,
and Sd is the standard deviation of the differences from the sample.
Now R also got a p-value.
So what's the p-value?
It's the likelihood of seeing data this extreme under the null hypothesis.
And, what we'll do here is look at twice,
it was a two tailed test, twice.
Now the t distribution is the one in play for us,
that's that letter t right there.
And p is just short for probability.
So, what we're trying to do is get some tail areas here.
So, we're going to take twice the tail area,
I'll look down at the left tail,
I'll pop my negative four in there.
Nine degrees of freedom and calculate a p-value.
If your p value is small,
you'll reject your null hypothesis and our p value is really quite small.
So we rejected the null hypothesis.
In general, if you have a hypothesis test,
different books have different details here,
but it's all they all rhyme.
They're all basically telling the same thing.
You're going to state clearly what your variables are
so that everybody knows including you what you're talking about.
State your null and a whole alternative hypotheses,
and then divide, decide upon rather a level of significance.
Once you've got that basic framework down those organizing principles,
go ahead and look at your data,
compute a test statistic,
and you'll run across very often z's and z's chi square as an f's.
These are kind of the big four in an elementary statistics course.
You'll find the p value corresponding to your test statistic,
and then you'll form a conclusion,
you'll reject or not reject typically.
Confidence intervals are,
there is a difference between the word confidence and probability.
Many people get very sticky on this and say that once an event has occurred,
you really can't talk about probability anymore.
Instead you must talk about confidence.
The basic idea is we're trying to give
a good indication of where we believe the actual meaning would be,
here it's going to be a mean difference.
The common form that you'll see for many confidence intervals is estimate.
That was our D Bar here, plus and minus,
some sort of table value multiplied by an estimated standard error.
It's not hard to really demonstrate where this comes from.
In our particular case,
we'll look at d bar,
plus and minus the T value,
times our standard error.
We already saw that R will print this out for you.
If you like to follow along and do a hand calculation yourself,
we've got the numbers right here.
It's just a direct substitution.
Standard error is just a shorthand notation
for the standard deviation of a sampling distribution.
And since we're dealing with means not individuals,
standard error is the right term to use.
Also, statistics are things that you compute from data.
Parameters are usually the things that you're trying to draw inferences on,
and it's a numerical descriptor about
either a theoretical distribution or an actual population.
And we can discuss type one and type two errors.
A lot of this is done in some more detail in the reading.
In this lecture you've learned how to use R to develop
graphical intuition into a data set as you're trying to answer a question,
and we've learned how to perform a statistical hypothesis,
we've reviewed the concept from basic statistics and shown how to do it in R.