统计学习的Matlab程序:包括各种假设检验,模型识别和线性回归等.

源代码在线查看: utest0.m

软件大小: 12 K
上传用户: yangw1027
关键词: Matlab 程序 假设检验 模型识别
下载地址: 免注册下载 普通下载 VIP

相关代码

				function [h,p,u,u1]=utest0(X,m,sigma,a,tail)
				%UTEST0 两个正态总体均值差的假设检验(t检验)
				%参考文献:《应用数理统计》(叶慈南编)p112.
				%TTEST  One-sample and paired-sample T-test.
				%调用格式:[h,p,t,t1]=utest0(X,m,sigma,a,tail)
				%X为样本,m为检验均值,sigma为已知的标准差,a为显著性水平
				%TAIL must be ''both'', ''right'', or ''left'', or 0, 1, or -1.'
				
				%By:Ji Lin
				%Email: linji@live.com
				%Blog: http://linji526.spaces.live.com
				%Date: 2007,2008/08/18
				
				if nargin				    tail=0;
				end
				if nargin				    a=0.05;
				end
				n=length(X);
				u=(mean(X)-m)*sqrt(n)/sigma;
				if tail == 0 % two-tailed test
				    u1=norminv(1-a/2,1,1);
				    p=1-2*normcdf(u,0,1);
				elseif tail == 1 % right one-tailed test
				    u1 = norminv(1-a,0,1);
				    p =1- normcdf(u, 0,1);        
				elseif tail == -1 % left one-tailed test
				    u1 = norminv(a,0,1);
				    p =normcdf(u, 0,1);
				else
				    error('stats:utest:BadTail',...
				          'TAIL must be ''both'', ''right'', or ''left'', or 0, 1, or -1.');
				end
				% Determine if the actual significance exceeds the desired significance
				if p 				    h = '拒绝H0';
				elseif p > a
				    h = '接受H0';
				else % isnan(p) must be true
				    h = NaN;
				end			

相关资源