function Partition_Variation_3D % AUTHOR: Spencer Hall % DATE: 3 June 2016 % PROJECT: Joint effects of hydroperiod, UVR, zooplankton, and host diversity on amphibian chytrid % PURPOSE: This is a 3D extension of the 2D variation partitioning model of % Legrendre and Legendre for multiple linear regression % Regression based variation partitioning based on LEGENDRE'S code % CALLS: findR2_OLS.m - this code calculations R2, then adjusted R2 % OUTPUT: Prints to screen the R2 values for the seven regression models fit % ... and the variation partitioning fractions as unlabeled matrices % Data used in Figure 6 and Table S1 % Figure used in final publication was modified from the original Matlab figure % load data load 'Pond_Data_3D.txt' -ascii; D = Pond_Data_3D; % split up data P = D(:,5); % Infection prevalence F = D(:,2); % Simpson's diversity index of all hosts Z = D(:,3); % Zoooplankton M = D(:,4); % Multi-season larvae of focal hosts % Fit regresion models % ... findR2_OLS spits back R2, then adjusted R2 % ... these models are defined in the accociated spreadsheet % ... Follows Legendre's approach [R1, aR1] = findR2_OLS([F,Z,M], P); % R2 with all three variables [R2, aR2] = findR2_OLS([Z,F], P); % R2 with two variables - Zooplankton & Host diversity ("F") [R3, aR3] = findR2_OLS([Z,M], P); % R2 with two variables - Zooplankton & Mulit-season larvae [R4, aR4] = findR2_OLS([F,M], P); % R2 with two variables - Host diversity ("F") & Mulit-season larvae [R5, aR5] = findR2_OLS(Z, P); % R2 with just one variable - Zooplankton [R6, aR6] = findR2_OLS(M, P); % R2 with just one variable - Mulit-season larvae [R7, aR7] = findR2_OLS(F, P); % R2 with just one variable - Host diversity ("F") % Do the variation partitioning now % ... in each line, there is fraction with regular R2, then adjusted R2 % ... (with 'a' following the symbol) a = R1 - R4; aa = aR1 - aR4; % Zooplankton alone - regular R2, then adjusted R2 b = R1 - R3; ba = aR1 - aR3; % Host diversity alone - regular R2, then adjusted R2 c = R1 - R2; ca = aR1 - aR2; % Multi-season larvae alone - regular R2, then adjusted R2 d = R1 - (R6 + a + b); da = aR1 - (aR6 + aa + ba); % shared between Host diveristy and Zooplankton e = R1 - (R5 + b + c); ea = aR1 - (aR5 + ba + ca); % shared between Host diversity and Multi-season larvae f = R1 - (R7 + a + c); fa = aR1 - (aR7 + aa + ca); % shared between Multi-season larvae and Zooplankton g = R1 - a - b - c - d - e - f; % shared by all three variables - regular R2 ga = aR1 - aa - ba - ca - da - ea - fa; % shared by all three variables - adjusted R2 % print results to screen disp('R2 values for each model 1 - 7') Rsq = [R1, R2, R3, R4, R5, R6, R7]' disp('adjusted R2 values for each model') aRsq = [aR1, aR2, aR3, aR4, aR5, aR6, aR7]' disp('Variation fraction for each component, a-g, regular R2') VarFract = [a, b, c, d, e, f, g]' disp('Variation fraction, but for adjusted R2') aVarFract = [aa, ba, ca, da, ea, fa, ga]' % make the graph using venn.m % first, calculate total areas if aa < 0 aa = 0; end if ba < 0 ba = 0; end if ca < 0 ca = 0; end if da < 0 da = 0; end if ea < 0 ea = 0; end if fa < 0 fa = 0; end if ga < 0 ga = 0; end Zta = aa + da + fa + ga; % total area for zooplankton Fta = ba + da + ea + ga; % total area for host diversity Mta = ca + ea + fa + ga; % total area for multi-season larvae Atot = [Zta, Fta, Mta] % total area packaged for code Aint = [da, fa, ea, ga] % intersection area % then, make the plot close(figure(1)) figure(1) set(gca, 'Box', 'off', 'TickDir', 'out', 'TickLength', [0.01, 0.01], 'LineWidth', 1,... % tick stuff, plot size 'Units', 'inches','FontName', 'Arial', 'FontSize', 10); % ... this is bottom panel set(gca, 'XTickLabel', num2str(get(gca,'XTick')','%0.1f')); venn(Atot, Aint)