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:
MATLAB applications, tutorials, examples, tricks, resources,...and a little bit of everything I learned ...
Subscribe to:
Posts (Atom)
my-alpine and docker-compose.yml
``` version: '1' services: man: build: . image: my-alpine:latest ``` Dockerfile: ``` FROM alpine:latest ENV PYTH...
-
It took me a while to figure out how to insert a space in Mathtype equations. This is especially useful when you write an equation with mult...
-
Recently I read post from Dr. Doug Hull's blog: http://blogs.mathworks.com/videos/2009/10/23/basics-volume-visualization-19-defining-s...
-
To get the slope of a pair of x and y, usually I first plot the curve and then add the trend line. Actually there are two functions i...