5 COMMON X(), Z(), S1(), S2(), S5(), D1(), D3(), R(), S6(), G$() 10 CLS 20 PRINT " STATISTICAL ECOLOGY: A PRIMER ON METHODS AND COMPUTING " 30 PRINT 40 PRINT " I N T E R A C T I V E B A S I C P R O G R A M " 50 PRINT 60 PRINT " D P C . B A S " 70 PRINT 80 PRINT " ------------------------------------------------------- " 90 PRINT " This program computes a DETRENDED PRINCIPAL COMPONENTS " 100 PRINT " ANALYSIS as a method of NONLINEAR ORDINATION. The " 110 PRINT " aim is to DETREND the ARCH-effect often observed in " 120 PRINT " a PRINCIPAL COMPONENTS ANALYSIS on data with MODERATE" 130 PRINT " NONLINEAR Species Relationships (see text, Chapt. 21)" 140 PRINT " (This method is also known as POLYNOMIAL ORDINATION)." 150 PRINT 160 PRINT " This PROGRAM fits a second-order POLYNOMIAL REGRESSION " 170 PRINT " to the SAMPLING UNIT Coordinates or Scores from the " 180 PRINT " first 2 COMPONENTS of a PCA. If the fit is good, " 190 PRINT " the results can be used to DETREND the ARCH into a " 200 PRINT " SINGLE component or axis. " 210 PRINT " ------------------------------------------------------- " 220 PRINT "PRESS ANY KEY TO CONTINUE" 230 IF INKEY$ = "" THEN 230 240 CLS 250 PRINT "- - - - - - - - - PART I. DATA ENTRY - - - - - - - - - - -": PRINT 260 PRINT "This program uses sampling unit (SU) coordinates on components " 270 PRINT " obtained from ordination methods, usually principal components" 280 PRINT " analysis (PCA), but this technique would apply to components " 290 PRINT " obtained from polar ordination (PO) or correspondence analysis" 300 PRINT " (COA), as well. However, this detrending procedure would only" 310 PRINT " be applied if an ARCH was evident in the pattern of SUs in the" 320 PRINT " ordination used.": PRINT 330 PRINT "The DATA is entered in the form of a MATRIX with " 340 PRINT " ROWS= Coordinates for the various components and COLUMNS=SUs. " 350 PRINT " For example:" 360 PRINT " SUs" 370 PRINT " 1 2 3 4 5" 380 PRINT " Components ----- ----- ----- ----- ----- " 390 PRINT " PC I -0.28 -0.11 +0.12 -0.50 +0.28 " 400 PRINT " PC II -0.62 +0.55 +0.78 0.00 -0.72 " 420 GOSUB 1760 430 PRINT 440 PRINT "Next, INPUT your CHOICE of the COMPONENT to be used as the" 450 PRINT " INDEPENDENT variable (X). Normally this would be the " 460 PRINT " first component (PC I); thus, if the SU coordinates for " 470 PRINT " PC I are in ROW 2 of the data matrix, enter a '2'.": PRINT 480 INPUT "ENTER ROW # for independent variable, X ? ", V1 490 IF V1 < 1 OR V1 > K THEN PRINT "out-of-range, try again": GOTO 480 500 PRINT 510 PRINT "Next, INPUT your CHOICE of COMPONENT to be used as the" 520 PRINT " DEPENDENT variable (Y). Normally this would be the " 530 PRINT " second component (PC II), thus, if the SU coordinates " 540 PRINT " for PC II are in ROW 1 of the data matrix, enter a '1'.": PRINT 550 INPUT "ENTER ROW # for dependent variable, Y ? ", V2 560 IF V2 < 1 OR V2 > K THEN PRINT "out-of-range, try again": GOTO 550 570 REM - Set up the data to be analyzed based on these choices of variables 580 G$(1) = " X ": G$(2) = " X^2": G$(3) = " Y " 590 FOR I = 1 TO N 600 Z(I, 1) = X(V1, I): Z(I, 2) = X(V1, I) * X(V1, I): Z(I, 3) = X(V2, I) 610 NEXT I: PRINT 620 PRINT "Would you like a listing of these SELECTED data, including the " 630 INPUT " values for X squared ? (Y/N) "; H$ 640 IF H$ = "N" OR H$ = "n" THEN GOTO 710 650 FOR J = 1 TO 3: PRINT G$(J); : FOR I = 1 TO N 660 PRINT USING "#####.##"; Z(I, J); 670 NEXT I: PRINT 680 NEXT J: PRINT 690 PRINT "PRESS ANY KEY TO CONTINUE" 700 IF INKEY$ = "" THEN 700 710 CLS : PRINT "- - PART II. Detrended Principal Components Analysis - -": PRINT 720 PRINT " Basic Statistics " 730 PRINT "Variable Mean Variance Std. Dev. Std. Error" 740 PRINT "-------- ------- ---------- ---------- -----------" 750 FOR J = 1 TO 3 760 S1(J) = 0: S2(J) = 0 770 FOR I = 1 TO N 780 S1(J) = S1(J) + Z(I, J) 790 S2(J) = S2(J) + Z(I, J) * Z(I, J) 800 NEXT I 810 D1(J) = S1(J) / N 820 D2 = (S2(J) - ((S1(J) * S1(J)) / N)) / (N - 1) 830 D3(J) = SQR(D2) 840 D4 = D3(J) / SQR(N) 850 PRINT USING "#####"; J; 860 PRINT USING "########.###"; D1(J); D2; D3(J); D4 870 NEXT J: PRINT 880 PRINT "PRESS ANY KEY TO CONTINUE" 890 IF INKEY$ = "" THEN 890 900 PRINT : PRINT "CORRELATIONS between the INDEPENDENT variable, X (PC I), and " 910 PRINT " the square of X (PC I squared), and the DEPENDENT variable," 920 PRINT " (PC II), which are needed for the polynomial calculations. " 930 PRINT 940 PRINT "Comparison Correlation Standard Degrees t " 950 PRINT " Var. Var. Coefficient Error Freedom Statistic " 960 PRINT " ---- ---- ----------- -------- ------- --------- " 970 R(3, 3) = 1 980 M = 3 - 1 990 FOR J = 1 TO M 1000 R(J, J) = 1 1010 FOR M1 = J TO M 1020 L = M1 + 1 1030 S3 = 0 1040 FOR I = 1 TO N 1050 S3 = S3 + Z(I, J) * Z(I, L) 1060 NEXT I 1070 D5 = N - 2 1080 S4 = S3 - ((S1(J) * S1(L)) / N) 1090 S5(J) = S2(J) - ((S1(J) * S1(J)) / N) 1100 S5(L) = S2(L) - ((S1(L) * S1(L)) / N) 1110 R(J, L) = S4 / (SQR(S5(J) * S5(L))) 1120 R(L, J) = R(J, L) 1130 R1 = R(J, L) * R(J, L) 1140 S6(J) = 1 - R1 1150 S7 = S6(J) / D5 1160 S8 = SQR(S7) 1170 T = R(J, L) / S8 1180 PRINT G$(J); G$(L); 1190 PRINT USING "#######.###"; R(J, L); S8; 1200 PRINT USING "##########"; D5; 1210 PRINT USING "########.###"; T 1220 NEXT M1 1230 NEXT J: PRINT 1240 PRINT "PRESS ANY KEY TO CONTINUE" 1250 IF INKEY$ = "" THEN 1250 1260 REM - ESTIMATION of SECOND-ORDER POLYNOMIAL REGRESSION PARAMETERS 1270 B1 = (R(1, 3) - (R(2, 3) * R(1, 2))) / (1 - (R(1, 2) * R(1, 2))) 1280 B2 = (R(2, 3) - (R(1, 3) * R(1, 2))) / (1 - (R(1, 2) * R(1, 2))) 1290 R2 = (R(1, 3) * B1) + (R(2, 3) * B2) 1300 PRINT 1310 PRINT "The Standardized Partial Regression Coefficients:" 1320 PRINT " B1 = "; 1330 PRINT USING "###.###"; B1; 1340 PRINT " and B2 = "; 1350 PRINT USING "###.###"; B2: PRINT 1360 B1 = B1 * D3(3) / D3(1) 1370 B2 = B2 * D3(3) / D3(2) 1380 B0 = D1(3) - (B1 * D1(1)) - (B2 * D1(2)) 1390 PRINT "The second-order POLYNOMIAL REGRESSION Equation with INTERCEPT " 1400 PRINT " and PARTIAL Regression Coefficients: " 1410 PRINT " Y = "; 1420 PRINT USING "###.###"; B0; 1430 PRINT " + ("; 1440 PRINT USING "###.###"; B1; 1450 PRINT " * X) + ("; 1460 PRINT USING "###.###"; B2; 1470 PRINT " * X^2) ": PRINT 1480 D5 = N - 2 - 1: F = (R2 / 2) / ((1 - R2) / D5) 1490 PRINT " Coefficient of Multiple Determination: R-SQ. = "; 1500 PRINT USING "###.###"; R2 1510 PRINT " F ratio = "; 1520 PRINT USING "###.###"; F; 1530 PRINT " at Degrees of Freedom = 2 /"; 1540 PRINT USING "###"; D5: PRINT 1550 PRINT "PRESS ANY KEY TO CONTINUE" 1560 IF INKEY$ = "" THEN 1560 1570 PRINT : PRINT "Would you like OUTPUT of SOLVED VALUES from -1 to +1 " 1580 INPUT " for Y (Yhat) to aid in PLOTTING the PARABOLA ? (Y/N) "; H$ 1590 IF H$ = "N" OR H$ = "n" THEN GOTO 1720 1600 PRINT " X Y " 1610 PRINT " ----- -----" 1620 X1 = 0 1630 FOR J = 1 TO 11 1640 Y1 = B0 + (B1 * X1) + (B2 * X1 * X1) 1650 PRINT USING "###.###"; X1; Y1 1660 IF J = 1 THEN GOTO 1700 1670 X2 = -1 * X1 1680 Y1 = B0 + (B1 * X2) + (B2 * X2 * X2) 1690 PRINT USING "###.###"; X2; Y1 1700 X1 = X1 + .1 1710 NEXT J: PRINT 1720 INPUT "Another Combination of CHOICES for Dependent and Independent Variables ? (Y/N) "; H$ 1730 IF H$ = "Y" OR H$ = "y" THEN GOTO 430 1740 PRINT : PRINT "END OF THE PROGRAM": CLEAR 1750 END 1760 REM - - - - - SUBROUTINE FOR DATA ENTRY - - - - - 1770 PRINT "Data INPUT options:" 1780 PRINT " Option 1 - Data already exists in a STORED data file" 1790 PRINT " Option 2 - Data is to be manually entered from keyboard" 1800 PRINT " (and subsequently STORED, if desired)": PRINT 1810 INPUT "Choose OPTION: Input 1 or 2 "; OPT 1820 IF OPT < 1 OR OPT > 2 THEN PRINT "value out-of-range, try again ": GOTO 1810 1830 INPUT "INPUT the NUMBER of SAMPLING UNITS (SUs) "; N 1840 INPUT "INPUT the NUMBER of COMPONENTS "; K: PRINT 1850 DIM X(K, N), Z(N, 3), S1(3), S2(3), S5(3), D1(3), D3(3), R(3, 3), S6(3), G$(3) 1860 IF OPT = 1 THEN GOTO 2040 ELSE IF OPT <> 2 THEN GOTO 1870 1870 PRINT 1880 PRINT "The data matrix is created one COLUMN (or SU) at a time," 1890 PRINT " that is, INPUT coordinates for SUs on components": PRINT 1900 FOR SU = 1 TO N: FOR SP = 1 TO K 1910 PRINT "Coordinate for SU "; SU; " on component "; SP; 1920 INPUT " = "; X(SP, SU) 1930 NEXT SP: NEXT SU 1940 INPUT "STORE This DATASET ON DISK ? (ENTER Y for YES / N for NO) "; A$ 1950 IF A$ = "N" OR A$ = "n" THEN GOTO 2110 ELSE GOTO 1960 1960 INPUT "Specify a name for this DATASET (e.g., DPC.DAT) "; OUTDAT$ 1970 INPUT "Specify DISK drive: ENTER A, B, C, etc. "; DD$ 1980 OUTDAT$ = DD$ + ":" + OUTDAT$ 1990 OPEN OUTDAT$ FOR OUTPUT AS #1 2000 FOR SU = 1 TO N: FOR SP = 1 TO K 2010 PRINT #1, X(SP, SU); 2020 NEXT SP: NEXT SU: PRINT 2030 GOTO 2110 2040 INPUT "Specify name of DATA File (e.g., DPC.DAT) "; DATAFIL$ 2050 INPUT "Specify DISK DRIVE where located: A, B, C, etc. "; DD$ 2060 FILENAM$ = DD$ + ":" + DATAFIL$ 2070 OPEN "I", #1, FILENAM$ 2080 FOR SU = 1 TO N: FOR SP = 1 TO K 2090 INPUT #1, X(SP, SU) 2100 NEXT SP: NEXT SU: PRINT 2110 INPUT "Would you like to list the DATA ? (Y for Yes / N for NO) "; A$ 2120 IF A$ = "Y" OR A$ = "y" THEN GOTO 2130 ELSE GOTO 2210 2130 PRINT "LISTING OF THE DATA SET: ROW = species, COLUMNS = SUs": PRINT 2140 FOR SP = 1 TO K 2150 FOR SU = 1 TO N 2160 PRINT X(SP, SU); 2170 NEXT SU: PRINT 2180 NEXT SP: PRINT 2190 PRINT "PRESS ANY KEY TO CONTINUE" 2200 IF INKEY$ = "" THEN 2200 2210 CLOSE #1 2220 RETURN