%Candace Metoyer %Statistics 135 Discussion 4-12-07 %Analysis of the Turtle Data clear;clc; format short format compact load turtledata.txt %Load the turtle data X = turtledata; x1 = X(:,1); x2 = X(:,2); x3 = X(:,3); [n, p] = size(X) %Compute the mean of each column (a p by 1 vector) Xbar = (mean(X))' %Compute the mean across each row (an n by 1 vector) %Xbar = mean(X,2) %Obtain the deviation vectors. d1 = x1 - Xbar(1)*ones(n,1); d2 = x2 - Xbar(2)*ones(n,1); d3 = x3 - Xbar(3)*ones(n,1); %Compute the sample variance matrix, S s11 = d1'*d1/(n-1); s22 = d2'*d2/(n-1); s33 = d3'*d3/(n-1); s12 = d1'*d2/(n-1); s13 = d1'*d3/(n-1); s23 = d2'*d3/(n-1); S = [s11 s12 s13; s12 s22 s23; s13 s23 s33] %Compute the generalized sample variance g_sample_variance = det(S) %Compute the total sample variance; t_sample_variance = trace(S) %Compute the sample correlation matrix, R r11 = 1; r22 = 1; r33 = 1; r12 = s12/sqrt(s11*s22); r13 = s13/sqrt(s11*s33); r23 = s23/sqrt(s22*s33); R = [r11 r12 r13; r12 r22 r23; r13 r23 r33] %Find the eigenvalues and eigenvectors of R [eigVEC, eigVAL] = eig(R) %Compute histograms for each variable figure %opens up a new figure window rhist(x1) %rhist.m forms a relative frequency histogram and hist.m uses the original counts. figure rhist(x2) figure rhist(x3) %Yikes. These plots don't look like Prof. Burman's. %We can adjust the histograms so that the bins %are centered on specific values. centers1 = 100:10:180; centers2 = 80:5:130; centers3 = 40:5:65; figure %opens up a new figure window rhist(x1,centers1') figure rhist(x2,centers2') figure rhist(x3,centers3') %Construct normal probability plots figure qqplot(x1) figure qqplot(x2) figure qqplot(x3) %Construct chi-square plots %Use function qqchi2.m %input is the n x p data matrix figure qqchi2(X) xlabel('Quantiles of the \chi_3^2 distribution') ylabel('d_j^2 Quantiles') title('Chi-square plot for the turtle data (female)')