Question

Solution of the Example Calculate Mean: Standard Deviation: S-- Σ(xi-x) Find the t-score: If it is 95% confidence limit (α-0.05), you can use the above Table For any other α values, use the online t-score calculator (http://stattrek.com/online-calculator/t-distribution.aspx) Input Degrees of Freedom v-N-1 and Cumulative Probability-1- (a/2), you obtain t-scores: t 1-a/2,v x-(q-a/2,V) Lower (1- a) Confidence Limit: VN Upper(1-α) Confidence Limit: x4(11-a/2,V)

t-statistic Table t-a/2. See an online calculator: http://stattrek.com/online-calculator/t-distribution.aspx 1 for a symmetric 95% probability interval 4.3027 1 for a symmetric 95% probability interval 2.2010 2.1788 2.1604 2.1448 2.1314 2.1199 2.1098 2.1009 2.0930 Degrees of freedom Degrees of freedom 3.1824 12 4 2.7764 13 2.5706 2.4469 2.3646 2.3060 2.2622 2.2281 15 16 17 18 19 10

Please comment code with steps

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Define the following function and save it in confid.m (We are taking the confidence level as input and hence are not just restricting to calculating for 95%) . (If your version of matlab allows including the functions in scripts, then no need to create a function file)

function to find the confidence interval The function takes the following inputs inputs XVector of Heasurements 5 6 7 8 9 10 CL - conf idence level of the reguired conf idence interval (in %) %outputs riv -mean value ucupper confidence limit 1c - Lower conf idence limit function [rnv, uc, lc]confidíx, CL) find the number of observat ions N in the vectro x 12 13 N-lengthix); find the samp le Xbar-1/N古sum (X) ; mean 15 16 17 find the samp le standard deviat ion s-sqrt (1/ (N-1)古surn ( (x-xbar ) .2)) ; 응find the alpha for conf idence level a= 1-CL/ 100; conf. level 19 20 calculate df=N-1 ; the degrees of freedom find the critical value of t ter it=tinv (1-a/ 2, df ) ; 23 2 4 25 2 6 27 calculate the lower (1-alpha) confidence limit calculate the upper (1-alpha) confidence limit assign xbar to rer, to output |the mean value lc xbar-tcrit*S/sqrt (N) 29end

Call the above function in the following code

set the measurement vector 2 - x= [ 19.1 22.2 16.9 19.4 20.2 18.0 21.1]; 3 assign the confidence level 4c1 95 6- 7 8- call the function to get the confidence interval [rev, uc, Ic] = confid (x, cl) ; print the results fprint f( The mean value is %.2f, and %d** confidence interval for me an is [8.3t,8.3t]ini,mv, ci, Ic,uc);

get the following output

The mea n value is 19.56, and 95% confidence interval for mean is [17.890,21.224]

All code in text format

---- The function ---

%function to find the confidence interval
%The function takes the following inputs
%inputs
% x - Vector of Measurements
% CL - confidence level of the required confidence interval (in %)
%outputs
% mv - mean value
% uc - upper confidence limit
% lc - Lower confidence limit
function [mv,uc,lc]= confid(x,CL)
%find the number of observations N in the vectro x
N=length(x);
% find the sample mean
xbar=1/N*sum(x);
% find the sample standard deviation
S=sqrt(1/(N-1)*sum((x-xbar).^2));
%find the alpha for confidence level conf.level
a=1-CL/100;
%calculate the degrees of freedom
df=N-1;
%find the critical value of t
tcrit=tinv(1-a/2,df);
%calculate the lower (1-alpha) confidence limit
lc=xbar-tcrit*S/sqrt(N);
%calculate the upper (1-alpha) confidence limit
uc=xbar+tcrit*S/sqrt(N);
% assign xbar to mv, to output the mean value
mv=xbar;
end

%---The main ----

%set the measurement vector
x=[19.1 22.2 16.9 19.4 20.2 18.0 21.1];
% assign the confidence level
cl=95;
% call the function to get the confidence interval
[mv,uc,lc]= confid(x,cl);
%print the results
fprintf(' The mean value is %.2f, and %d%% confidence interval for mean is [%.3f,%.3f] ',mv,cl,lc,uc);

Add a comment
Know the answer?
Add Answer to:
Please comment code with steps Solution of the Example Calculate Mean: Standard Deviation: S-- Σ(xi-x) Find...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT