




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、Matlab統(tǒng)計工具箱Getting StartedToolbox functions and GUIsOrganizing DataData arrays and groupsDescriptive StatisticsData summariesStatistical VisualizationData patterns and trendsProbability DistributionsModeling data frequencyRandom Number GenerationTopics in random number generationHypothesis TestsInfe
2、rences from dataAnalysis of VarianceModeling data varianceRegression AnalysisContinuous data modelsMultivariate MethodsVisualization and reductionCluster AnalysisIdentifying data categoriesClassificationCategorical data modelsMarkov ModelsStochastic data modelsDesign of ExperimentsSystematic data co
3、llectionStatistical Process ControlProduction monitoring方差分析ANOVA Operationsanova1One-way analysis of varianceanova2Two-way analysis of varianceanovanN-way analysis of varianceaoctoolInteractive analysis of covariancedummyvarCreate dummy variablesfriedmanFriedman's testkruskalwallisKruskal-Walli
4、s testmanova1One-way multivariate analysis of variancemanovaclusterDendrogram of group mean clusters following MANOVAmultcompareMultiple comparison test方差分析模型方差分析是分析試驗(或觀測)數(shù)據(jù)的一種統(tǒng)計方法。在工農業(yè)生產(chǎn)和科學研究中,經(jīng)常要分析各種因素及因素之間的交互作用對研究對象某些指標值的影響。這時需要用到方差分析。利用方差分析,我們能推斷哪些因素對所考察指標的影響是顯著的,哪些是不顯著的。方差分析包括了:單因素方差分析、雙因素方差分析
5、和多因素方差分析。單因素方差分析單因素方差分析問題:某一因素(A)對結果()的影響分析。一般情況下,假設因素A有個不同的水平。單因素方差分析模型如下:其中表示在第組(水平)第個觀察值,為總的(的 )均值,為第組所的均值且滿足,表示第組第個樣本的誤差,為第組的數(shù)據(jù)個數(shù)且。方差分析的目的是要基于數(shù)據(jù)分析確定這組數(shù)據(jù)的均值有沒有顯著性差異,即假設檢驗問題: v.s. 不全相等。 (1)原假設表明因素A對的值沒有影響。格式p = anova1(X)p = anova1(X,group)p = anova1(X,group,displayopt)p,table = anova1(.)p,table,st
6、ats = anova1(.)實例 1Create X with columns that are constants plus random normal disturbances with mean zero and standard deviation one:X = meshgrid(1:5)X = 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5X = X + normrnd(0,1,5,5)X = 1.3550 2.0662 2.4688 5.9447 5.4897 2.0693 1.7611 1.4864 4.8826 6.322
7、2 2.1919 0.7276 3.1905 4.8768 4.6841 2.7620 1.8179 3.9506 4.4678 4.9291 -0.3626 1.1685 3.5742 2.1945 5.9465Perform one-way ANOVA:p = anova1(X)p = 7.9370e-006the very small p value indicates that differences between column means are highly significant. The probability of this outcome under the null h
8、ypothesis (that samples drawn from the same population would have means differing by the amounts seen in X) is equal to the p value.實例 2The following example is from a study of the strength of structural beams in Hogg. The vector strength measures deflections of beams in thousandths of an inch under
9、 3,000 pounds of force. The vector alloy identifies each beam as steel (鐵'st'), alloy 1 (合金1'al1'), or alloy 2 (合金2'al2'). (Although alloy is sorted in this example, grouping variables do not need to be sorted.) The null hypothesis is that steel beams are equal in strength to
10、 beams made of the two more expensive alloys.strength = 82 86 79 83 84 85 86 87.74 82 78 75 76 77 .79 79 77 78 82 79;alloy = 'st','st','st','st','st','st','st','st',. 'al1','al1','al1','al1','al1'
11、,'al1',. 'al2','al2','al2','al2','al2','al2'p = anova1(strength,alloy)p = 1.5264e-004雙因素方差分析模型雙因素方差分析問題。一般地,不妨假設因素A有個水平,因素B有個水平。在雙因素(多因素方差)分析中,不僅要考慮每個因素的影響,有時還要考慮因素之間的交互作用。下面是考慮有交互作用的雙因素方差分析的模型如下:其中表示A因素第組B因素第組第個樣本的觀察值,為總的均值,為A因素第組的均值,為B因素第組的均值
12、,表示A因素第組B因素第組交互作用的均值,滿足。方差分析的目的是要基于數(shù)據(jù)分析確定兩因素是否存在交互作用,各因素不同組的均值有沒有顯著性差異,也就是假設檢驗問題: v.s. 不全相等, (2) v.s. 不全相等, (3) v.s. (4)格式p = anova2(X,reps)p = anova2(X,reps,displayopt)p,table = anova2(.)p,table,stats = anova2(.)實例The data below come from a study of popcorn brands and popper type (Hogg 1987). The c
13、olumns of the matrix popcorn are brands (Gourmet, National, and Generic). The rows are popper type (Oil and Air.) The study popped a batch of each brand three times with each popper. The values are the yield in cups of popped popcorn. load popcornpopcornpopcorn = 5.5000 4.5000 3.5000 5.5000 4.5000 4
14、.0000 6.0000 4.0000 3.0000 6.5000 5.0000 4.0000 7.0000 5.5000 5.0000 7.0000 5.0000 4.5000p = anova2(popcorn,3)p = 0.0000 0.0001 0.7462回歸分析Linear RegressioncoxphfitCox proportional hazards regressiondummyvarCreate dummy variablesglmfitGeneralized linear model regressionglmvalGeneralized linear model
15、valuesinvpredInverse predictionleverageLeveragemnrfitMultinomial logistic regressionmnrvalMultinomial logistic regression valuesmvregressMultivariate linear regressionmvregresslikeNegative log-likelihood for multivariate regressionplsregressPartial least-squares regressionpolyconfPolynomial confiden
16、ce intervalspolytoolInteractive polynomial fittingregressMultiple linear regressionregstatsRegression diagnosticsridgeRidge regressionrobustdemoInteractive robust regressionrobustfitRobust regressionrsmdemoInteractive response surface demonstrationrstoolInteractive response surface modelingstepwiseI
17、nteractive stepwise regressionstepwisefitStepwise regressionx2fxConvert predictor matrix to design matrix回歸分析模型模型假設和相關問題設變量與多個變量 (p>1)有線性相關關系,相應的觀察數(shù)據(jù)為,。我們討論的多元線性回歸模型為:其中和是未知參數(shù)。格式b = regress(y,X)b,bint = regress(y,X)b,bint,r = regress(y,X)b,bint,r,rint = regress(y,X)b,bint,r,rint,stats = regress(y
18、,X). = regress(y,X,alpha)實例導入數(shù)據(jù)cars; 確定weight 和 horsepower 作為自變量(預測變量), mileage 為響應變量:load carsmallx1 = Weight;x2 = Horsepower; % Contains NaN datay = MPG;計算有交互作用項的線性回歸模型的回歸系數(shù):X = ones(size(x1) x1 x2 x1.*x2;b = regress(y,X) % Removes NaN datab = 60.7104 -0.0102 -0.1882 0.0000Plot the data and the mo
19、del:scatter3(x1,x2,y,'filled')hold onx1fit = min(x1):100:max(x1);x2fit = min(x2):10:max(x2);X1FIT,X2FIT = meshgrid(x1fit,x2fit);YFIT = b(1) + b(2)*X1FIT + b(3)*X2FIT + b(4)*X1FIT.*X2FIT;mesh(X1FIT,X2FIT,YFIT)xlabel('Weight')ylabel('Horsepower')zlabel('MPG')view(50,10)
20、主成分分析Principal Component AnalysisbarttestBartlett's testparetoPareto chartpcacovPrincipal component analysis on covariance matrixpcaresResiduals from principal component analysisprincompPrincipal component analysis on data模型在研究某個問題時涉及到個變量(指標)(記為列向量,且有均值向量和方差協(xié)方差矩陣)。通常較大且這些指標之間存在一定程度的相關性。因此我們考慮用以下
21、線性變換將這個變量轉換成新的個兩兩不相關的變量:記,且限定,則上述的線性變換中的變換矩陣的轉置。由于這組新的變量中任意兩個不相關,即對任意有。而且變量中每一個變量的方差依次是余下所有變量中最大的,因此有。方差越大,包含的信息就越多。我們稱為的第主成分。理論上可以證明第個主成分對應于的方差協(xié)方差矩陣的第個特征值,與特征值相應的標準化特征向量記為。且有的特征根是主成分的方差,即 ,這里有。因此主成分的方差協(xié)方差矩陣為對角矩陣diag()。格式COEFF,SCORE = princomp(X)COEFF,SCORE,latent = princomp(X)COEFF,SCORE,latent,tsq
22、uare = princomp(X). = princomp(X,'econ')實例Compute principal components for the ingredients data in the Hald data set, and the variance accounted for by each component.load hald;pc,score,latent,tsquare = princomp(ingredients);pc,latentpc = 0.0678 -0.6460 0.5673 -0.5062 0.6785 -0.0200 -0.5440
23、-0.4933 -0.0290 0.7553 0.4036 -0.5156 -0.7309 -0.1085 -0.4684 -0.4844latent = 517.7969 67.4964 12.4054 0.2372The following command and plot show that two components account for 98% of the variance: cumsum(latent)./sum(latent)ans = 0.86597 0.97886 0.9996 1biplot(pc(:,1:2),'Scores',score(:,1:2
24、),'VarLabels',.'X1' 'X2' 'X3' 'X4')因子分析Factor AnalysisfactoranFactor analysis模型假設類似于在主成分分析中的情形,在研究某個問題時涉及到個容易觀測的變量(記為列向量)。其均值向量,方差協(xié)方差矩陣)。我們假定存在個潛在相互獨立的的公共因子(變量)(記為列向量)和個相互獨立的特殊因子變量(記為列向量)滿足以下的模型:其中,記為。相互獨立。模型用矩陣向量形式可表示為其中被稱為因子載荷矩陣。格式lambda = factoran(X,m)lambd
25、a,psi = factoran(X,m)lambda,psi,T = factoran(X,m)lambda,psi,T,stats = factoran(X,m)lambda,psi,T,stats,F = factoran(X,m). = factoran(.,param1,val1,param2,val2,.)實例1導入carbig數(shù)據(jù), 用兩因子擬合默認的模型.load carbigX = Acceleration Displacement Horsepower MPG Weight; X = X(all(isnan(X),2),:);Lambda,Psi,T,stats,F = f
26、actoran(X,2,. 'scores','regression');inv(T'*T) % Estimated correlation matrix of F, = eye(2)Lambda*Lambda'+diag(Psi) % Estimated correlation matrixLambda*inv(T) % Unrotate the loadingsF*T' % Unrotate the factor scoresbiplot(Lambda,. % Create biplot of two factors 'Lin
27、eWidth',2,. 'MarkerSize',20)實例 2Although the estimates are the same, the use of a covariance matrix rather than raw data doesn't let you request scores or significance level:Lambda,Psi,T = factoran(cov(X),2,'xtype','cov')Lambda,Psi,T = factoran(corrcoef(X),2,'xtyp
28、e','cov')實例 3斜交旋轉Use promax rotation:Lambda,Psi,T,stats,F = factoran(X,2,'rotate','promax',. 'powerpm',4);inv(T'*T) % Est'd corr of F, % no longer eye(2)Lambda*inv(T'*T)*Lambda'+diag(Psi) % Est'd corr of XPlot the unrotated variables with obliq
29、ue axes superimposed.invT = inv(T)Lambda0 = Lambda*invTline(-invT(1,1) invT(1,1) NaN -invT(2,1) invT(2,1), . -invT(1,2) invT(1,2) NaN -invT(2,2) invT(2,2), . 'Color','r','linewidth',2)hold onbiplot(Lambda0,. 'LineWidth',2,. 'MarkerSize',20)xlabel('Loadings
30、 for unrotated Factor 1')ylabel('Loadings for unrotated Factor 2')聚類分析Hierarchical ClusteringclusterConstruct agglomerative clusters from linkagesclusterdataConstruct agglomerative clusters from datacophenetCophenetic correlation coefficientinconsistentInconsistency coefficientlinkageCre
31、ate agglomerative hierarchical cluster treepdistPairwise distance between pairs of objectspdist2Pairwise distance between two sets of observationssquareformFormat distance matrix系統(tǒng)聚類法是聚類分析中應用最為廣泛的一種方法.它的基本原理是:首先將一定數(shù)量的樣品(或指標)各自看成一類,然后根據(jù)樣品(或指標)的親疏程度,將親疏程度最高的兩類合并,然后重復進行,直到所有的樣品都合成一類.衡量親疏程度的指標有兩類:距離、相似系
32、數(shù).1.常用距離1)歐氏距離假設有兩個維樣本和,則它們的歐氏距離為2)標準化歐氏距離假設有兩個維樣本和,則它們的標準化歐氏距離為其中:表示個樣本的方差矩陣,表示第列的方差.3)馬氏距離假設共有個指標,第個指標共測得個數(shù)據(jù)(要求):, 于是,我們得到階的數(shù)據(jù)矩陣,每一行是一個樣本數(shù)據(jù).階數(shù)據(jù)矩陣的階協(xié)方差矩陣記做.兩個維樣本和的馬氏距離如下:馬氏距離考慮了各個指標量綱的標準化,是對其它幾種距離的改進.馬氏距離不僅排除了量綱的影響,而且合理考慮了指標的相關性.4)布洛克距離兩個維樣本和的布洛克距離如下:5)閔可夫斯基距離兩個維樣本和的閔可夫斯基距離如下:注:時是布洛克距離;時是歐氏距離.6)余弦距
33、離這是受相似性幾何原理啟發(fā)而產(chǎn)生的一種標準,在識別圖像和文字時,常用夾角余弦為標準.7)相似距離2.MATLAB中常用的計算距離的函數(shù)假設我們有階數(shù)據(jù)矩陣,每一行是一個樣本數(shù)據(jù). 在MATLAB中計算樣本點之間距離的內部函數(shù)為y=pdist(x) 計算樣本點之間的歐氏距離y=pdist(x,'seuclid') 計算樣本點之間的標準化歐氏距離y=pdist(x,'mahal') 計算樣本點之間的馬氏距離y=pdist(x,'cityblock') 計算樣本點之間的布洛克距離y=pdist(x,'minkowski') 計算樣本點之
34、間的閔可夫斯基距離y=pdist(x,'minkowski',p) 計算樣本點之間的參數(shù)為p的閔可夫斯基距離y=pdist(x,'cosine') 計算樣本點之間的余弦距離y=pdist(x,'correlation') 計算樣本點之間的相似距離另外,內部函數(shù)yy=squareform(y)表示將樣本點之間的距離用矩陣的形式輸出.3.常用的聚類方法常用的聚類方法主要有以下幾種:最短距離法、最長距離法、中間距離法、重心法、平方和遞增法等等.4. 創(chuàng)建系統(tǒng)聚類樹假設已經(jīng)得到樣本點之間的距離y,可以用linkage函數(shù)創(chuàng)建系統(tǒng)聚類樹,格式為z=link
35、age(y).其中:z為一個包含聚類樹信息的(m-1)×3的矩陣.例如:z=2.000 5.000 0.23.000 4.000 1.28則z的第一行表示第2、第5樣本點連接為一個類,它們距離為0.2;則z的第二行表示第3、第4樣本點連接為一個類,它們距離為1.28.在MATLAB中創(chuàng)建系統(tǒng)聚類樹的函數(shù)為z=linkage(y) 表示用最短距離法創(chuàng)建系統(tǒng)聚類樹z=linkage(y,'complete') 表示用最長距離法創(chuàng)建系統(tǒng)聚類樹z=linkage(y,'average') 表示用平均距離法創(chuàng)建系統(tǒng)聚類樹z=linkage(y,'cent
36、roid') 表示用重心距離法創(chuàng)建系統(tǒng)聚類樹z=linkage(y,'ward') 表示用平方和遞增法創(chuàng)建系統(tǒng)聚類樹格式T = cluster(Z,'cutoff',c)T = cluster(Z,'cutoff',c,'depth',d)T = cluster(Z,'cutoff',c,'criterion',criterion)T = cluster(Z,'maxclust',n)實例比較Fisher iris數(shù)據(jù)的聚類結果和類別數(shù)據(jù):load fisheririsd =
37、 pdist(meas);Z = linkage(d);c = cluster(Z,'maxclust',3:5);crosstab(c(:,1),species)ans = 0 0 2 0 50 48 50 0 0crosstab(c(:,2),species)ans = 0 0 1 0 50 47 0 0 2 50 0 0crosstab(c(:,3),species)ans = 0 4 0 0 46 47 0 0 1 0 0 2 50 0 0判別分析Discriminant AnalysisclassifyDiscriminant analysismahalMahalan
38、obis distance判別分析概說在已知研究對象分成若干類型,并已取得各種類型的一批已知樣品的觀測數(shù)據(jù),在此基礎上根據(jù)某些準則建立判別式,然后對未知類型的樣品進行判別分類。距離判別法首先根據(jù)已知分類的數(shù)據(jù),分別計算各類的重心,計算新個體到每類的距離,確定最短的距離(歐氏距離、馬氏距離)Fisher判別法利用已知類別個體的指標構造判別式(同類差別較小、不同類差別較大),按照判別式的值判斷新個體的類別Bayes判別法計算新給樣品屬于各總體的條件概率,比較概率的大小,然后將新樣品判歸為來自概率最大的總體 判別分析是利用原有的分類信息,得到體現(xiàn)這種分類的函數(shù)關系式(稱之為判別函數(shù),一般是與分類相關的若干個指標的線性關系式),然后利用該函數(shù)去判斷未知樣品屬于哪一類。Matlab中對于給定的數(shù)據(jù),用c
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 社區(qū)孤獨癥患者關懷的個人方法計劃
- 分配任務與跟進進度的秘書工作計劃
- 品牌資產(chǎn)與市場風險的關聯(lián)研究計劃
- 全面提升團隊績效的年度規(guī)劃計劃
- 強化職能部門之間的配合計劃
- 如何選擇合適的品牌推廣渠道計劃
- 2025年物位儀項目建議書
- 2025年數(shù)字貨幣金融項目發(fā)展計劃
- 2025年瀝青試驗儀器項目發(fā)展計劃
- 新員工入職引導及工作流程簡明教程
- 2024年司法考試完整真題及答案
- 【化學】高中化學手寫筆記
- 2024年執(zhí)業(yè)藥師繼續(xù)教育專業(yè)答案
- 2024年安全員-C證考試題庫及答案(1000題)
- 膽管惡性腫瘤護理查房課件
- 義務教育語文課程標準2022年版
- 公務員入職登記表
- 九年級新目標英語單詞表默寫最新版
- 臨水臨電計算公式案例
- 2022新教科版六年級科學下冊第二單元《生物的多樣性》全部教案(共7節(jié))
- PEP人教版小學英語單詞四年級上冊卡片(可直接打印)
評論
0/150
提交評論