Monday, May 3, 2010

A computer experiment on statistics: confidence interval for mean and variances of normal population

I am reading Statistics for Science and Engineering by Kinney today.In this book, there is a computer experiment assignment like this:

Select 1000 samples, each of size 10, from a N(10,5) distribution. Calculated the mean for each and a 95% confidence interval for u for each sample. Count the number of these confidence intervals that actually contain the true mean, 10.

I used MATLAB to do this.

clc;
clear all;
close all;
% Generate a normally distributed population.
Po=normrnd(10,5,[1,100000]);
SampleSize=10;
SampleNumber=10000;
%plot Po and histogram Po
figure
plot(Po);
figure
hist(Po, 100);

%take samples, each of size 'SampleSize'
Sa=[];
for i=1:SampleNumber
    for j=1:SampleSize
        index=round(abs(randn(1)*(length(Po)/10-1)))+1;
        Sa(i,j)=Po(index);
    end
end

%calculate the 95% confidence interval of each sample
mean=[];
interval=[];
for i=1:SampleNumber
    mean(i)=sum(Sa(i,:))/SampleSize;
    interval(i,1)=mean(i)-(1.96*5/sqrt(SampleSize));
    interval(i,2)=mean(i)+(1.96*5/sqrt(SampleSize));
end

%count the samples that contain 10
count=0;
for i=1:SampleNumber
    if interval(i,1)>=10 || interval(i,2)<=10
        count=count+1;
    end
end
count/SampleNumber

The results are around 0.05, which means that those confidence intervals have 5% chance not containing the true mean, 10. That's why those are 95% confidence intervals.


Plot of the population:
Histogram of the population:

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...