Anova1 < Matlab < Mathe-Software < Mathe < Vorhilfe
|
Status: |
(Frage) beantwortet | Datum: | 08:48 Sa 16.06.2007 | Autor: | makabeli |
Hallo,
ich soll ne Varianzanalyse mit Matlab machen, aber in den Daten die ich bekommen habe sind NaN drin, wie geh ich denn damit um?
|
|
|
|
Status: |
(Antwort) fertig | Datum: | 18:09 Sa 16.06.2007 | Autor: | BKM |
Hallo.
Ich könnte mir vorstellen, dass dieses Programm bei den fehlenden Daten helfen kann. Ansonsten einfach an die Gegebenheiten anpassen.
Beste Grüße.
% Program to compute a covariance matrix ignoring NaNs
% Usage: C = nancov(A,B)
% NANCOV calculates the matrix product A*B ignoring NaNs by replacing them
% with zeros, and then normalizing each element C(i,j) by the number of
% non-NaN values in the vector product A(i,:)*B(:,j).
%
% A - left hand matrix to be multiplied
% B - right hand matrix to be multiplied
% C - resultant covariance matrix
% Example: A = [1 NaN 1] , B = [1
% 1
% 1]
% then nancov(A,B) is 2/2 = 1
function [C]=nancov(A,B);
NmatA=~isnan(A); % Counter matrix
NmatB=~isnan(B);
A(isnan(A))=0; % Replace NaNs in A,B, and counter matrices
B(isnan(B))=0; % with zeros
Npts=NmatA*NmatB;
C=(A*B)./Npts;
% NANEOF.M
% Function to compute EOFs from demeaned data with NaNs:
% function [B,vars,amps]=naneof(anom);
% Computes EOFs of ROW DIMENSION in anom matrix
function [B,vars,amps]=naneof(anom);
%-----------------------------------------------------------------------
% Compute covariance of matrix with NaNs
Cov=nancov(anom,anom');
%-----------------------------------------------------------------------
% Compute eigenvectors (EOFs), eigenvalues (variances of amplitudes) of
% data covariance matrix
[B,D]=eig(Cov); % B = EOFs, diag(D) = eigenvalues
vars=flipud(diag(D)); % eigenvalues = variances of each amplitude
% EIG outputs from low to high, so flip column
% to order from high to low
B=fliplr(B); % Flip columns left/right to correspond
% to adjusted ordering of amplitudes
%-----------------------------------------------------------------------
% Put 0's in for NaNs in ANOM matrix to be able to compute amplitudes
anom(isnan(anom))=0;
amps=B'*anom; % amplitudes
%-----------------------------------------------------------------------
|
|
|
|