00:01
For this problem to begin, i'll note that when we're looking for a 90 % confidence interval, we'll have that it's given by our sample mean, plus or minus, since we're dealing with small sample sizes here, we'll use the t statistic for n minus 1 degrees of freedom.
00:20
We have samples of size 5 here, so we want 4 degrees of freedom, a one -tail proportion of 0 .05, times our sample standard deviation divided by the square root of our sample size.
00:34
Now i'm actually going to go directly to question 3, because most of what i'm going to do for question 3 in terms of the r code is going to be applicable to question 2.
00:44
It's just a matter of if we are generating the samples ourselves, or if we're working with the pre -made samples given to us.
00:52
All right, so i just realized that i have an absolutely ancient version of r installed currently.
00:56
Hopefully that's not going to cause any problems, but i'll create a new script here and go through.
01:01
So first we're asked to draw 100 samples of size 5 from the above population.
01:06
Now i believe i've seen another question submitted by the same user here, so i believe i actually do have what the underlying population distribution should be, and i'm just checking that now.
01:20
So i'll note, and one second here, i'll zoom in a little bit here for visibility if i can.
01:27
One moment.
01:28
All right, so to begin in my script here, i'll note that we're told that x is distributed following a normal distribution with a mean value of 5 and a sigma squared population variance equal to 4.
01:48
So that's at least what i'm working from.
01:51
Of course, you can adjust this as necessary.
01:54
Now we're asked to draw 100 samples of size 5 from the above population.
01:58
So what i'll do, i'll begin by specifying that the number of samples is going to be 500, or pardon me, not 500, it's 100.
02:11
Then we'll want to loop to generate samples.
02:20
So we'll begin by generating our variable that will hold all of our sample values.
02:25
So we say e is a list, mode equals vector, and the length is equal to our number of samples.
02:43
Then we say for i in 1 up to our number of samples, we say that e element i is our norm, n equals 5, mean equals 5, and standard deviation would be equal to 2 since the population variance is 4.
03:14
Now one moment here.
03:16
All right, pardon me, i had to pause for a moment.
03:18
So continuing along here, we, at this point for the code, we would have our samples generated, all 100 of them.
03:25
The next thing that we need to do is determine if the mean is in the confidence interval.
03:35
Now, you don't necessarily need to use the exact steps that i'm using here.
03:39
The approach that i'll take is to define a function to test this.
03:45
So i'll call the function mean in ci.
03:54
It's a function where i'll pass in the lower bound, lb, the upper bound, ub, and the mean.
04:02
Or actually, i'll call the mean mu.
04:08
And this will be a pretty simple function.
04:11
We'll say return as dot integer.
04:13
So we'll be returning a boolean value translated into an integer, which means that it will be 1 if true and 0 if false.
04:23
So we say return as dot integer, mean greater than or equal to the lower bound, and or pardon me, that should be mu, not mean, mu greater than or equal to lower bound, and mu less than or equal to upper bound.
04:48
Then we generate the confidence interval for each sample.
04:56
And again, the approach that i'll take here is to define a function for this, where i'm going to be programming in ahead of time the level of confidence that we want.
05:09
I believe, what is it, 90 %? yeah.
05:13
Define function for 90 % confidence, and i'll also be hard coding in the sample size, just noting that.
05:24
So we'll say generate confidence interval.
05:27
It's a function where we pass in just our sample.
05:36
We have that our ci is going to be a column vector, where the first value is going to be the mean of the sample.
05:50
Oh, actually, let me back up here.
05:52
The thing that i'll do ahead of time here is find the critical t value, which we find by using the command qt, 0 .954, since we should have 5 % in one tail, in this case the right tail, and 4 degrees of freedom.
06:18
Then we generate our confidence interval.
06:21
Actually, to keep this from getting too messy, i'll also calculate ahead of time the standard error, or actually, i'll just calculate the margin of error ahead of time.
06:33
So the margin of error is going to be given by the standard deviation of the sample divided by the square root of the sample size times our t value that we've calculated.
06:45
So then the confidence interval, which we'll be returning, the first value is just the mean of the sample minus the margin of error, and the second value is the mean of the sample plus the margin of error.
06:59
So then we want to return the confidence interval.
07:09
Now, since i've done quite a bit of work here, i'm going to quickly run all of this, make sure that i don't get any errors here, and now i'll test, let's see here, what's our first sample? okay, so we can see our first sample value is there...