home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / educ / pstat1.zip / CFIT.DOC next >
Text File  |  1986-12-17  |  23KB  |  454 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                         Exploratory Regression using CFIT
  7.  
  8.  
  9.                                Copyright (C) 1986
  10.  
  11.                                 Joseph C. Hudson
  12.  
  13.  
  14.  
  15.  
  16.         Introduction
  17.  
  18.  
  19.              CFIT fits up to 196 different curves to paired data using
  20.         least squares regression. The program can report results sorted
  21.         by F value or by adjusted coefficient of determination. It can
  22.         plot the observed data together with any of the fitted curves.
  23.         CFIT can report a variety of diagnostic information, including
  24.         histograms of residuals, anova tables and various standard
  25.         errors. Fitted Y values may be calculated.  The regressions
  26.         generated by CFIT can be saved to disk for future use.
  27.  
  28.         Data Requirements
  29.  
  30.              CFIT accepts data in SDA, space delimited ASCII, format.
  31.         In SDA format, variables are in columns and observations are in
  32.         rows. Each row may be in free format with one or more spaces
  33.         separating each value. Tabs may be used as separators, but not
  34.         commas. The data set should contain only numbers, no letters
  35.         or symbols (except minus signs and decimal points.) Missing
  36.         data must be coded with some value, not just left out, since
  37.         each row must have the same number of entries. Any number that
  38.         does not otherwise occur in the data set can serve as the miss-
  39.         ing value code. There can be up to 250 rows of data and any
  40.         number of columns. CFIT will only read the two columns it needs,
  41.         the column of X values and the column of Y values.
  42.  
  43.         Printer Requirements
  44.  
  45.             CFIT uses printer control codes for reset printer, formfeed,
  46.         condensed pitch, unidirectional printing, 6/72 inch linefeed and
  47.         12/72 inch linefeed. These codes only appear once in the source
  48.         code, in the procedure SetPrintVars. Changing these and recom-
  49.         piling will adapt CFIT to any printer capable of these actions.
  50.         The unidirectional print command is fairly important, since CFIT
  51.         prints tables and graphs that can look ragged without it. CFIT
  52.         comes with printer codes that work with Epson FX-80, LX-80 and
  53.         RX-80 and Star Gemini-Delta printers. The codes do not work with
  54.         Star SG10 or Epson LQ printers.
  55.  
  56.         Running CFIT
  57.  
  58.              CFIT1287 uses the 8087 chip, so if one is not installed,
  59.         use CFIT12, which does not use the 8087. Have the data file and
  60.         any output files from previous runs in the same directory. To
  61.         run, just type CFIT12 ( or CFIT1287) and respond to the prompts.
  62.  
  63.  
  64.         CFIT                                                       Page 2
  65.  
  66.  
  67.              CFIT first asks you to turn your printer on and set it to
  68.         top of form. After doing this, strike any key and the printer
  69.         will be set up. CFIT keeps track of how many lines have been
  70.         printed and avoids splitting output over page boundaries when-
  71.         ever possible. If things should get messed up, you can setup
  72.         the printer again from the main menu (option U).
  73.  
  74.  
  75.         The Screens
  76.  
  77.              The first screen CFit presents is
  78.  
  79.         *==============================================================*
  80.         |                                                              |
  81.         |   C Compute Y Hat Values                                     |
  82.         |   D Print Details of a Fit                                   |
  83.         |   F Find Y in Original Units Given Y in Transformed Units    |
  84.         |   H Print Histogram Of Residuals                             |
  85.         |   L List Files On Disk                                       |
  86.         |   N Run New Regression                                       |
  87.         |   P Plot Fitted Curve                                        |
  88.         |   Q Quit                                                     |
  89.         |   R Report Regression Results                                |
  90.         |   S Save Regresions to Disk                                  |
  91.         |   T Print Table of Residuals                                 |
  92.         |   U Setup Printer                                            |
  93.         |                                                              |
  94.         |   You can only use the G, L, N and Q options now.            |
  95.         *==============================================================*
  96.  
  97.         The first time through, a regression needs to be run. responding
  98.         N prompts the following questions :
  99.  
  100.         *==============================================================*
  101.         |                                                              |
  102.         | What is the name of the data file? SAMPLE.SDA                |
  103.         |                                                              |
  104.         | There are 17 rows and 2 columns of data.                     |
  105.         |                                                              |
  106.         |                                                              |
  107.         | Which column contains X? 1                                   |
  108.         | Which column contains Y? 2                                   |
  109.         |                                                              |
  110.         |                                                              |
  111.         | Do you want to omit any X or Y values ? N                    |
  112.         |                                                              |
  113.         *==============================================================*
  114.  
  115.              The responses shown can be used to run the sample data. If
  116.         you want to omit some X and/or Y values, like codes for missing
  117.         data, answering Y to the last question will prompt a series of
  118.         questions allowing you to specify values to be omitted.
  119.  
  120.  
  121.         CFIT                                                       Page 3
  122.  
  123.  
  124.              Entering G at the original prompt will cause the response
  125.  
  126.      *====================================================================*
  127.      |                                                                    |
  128.      |The data file and the output files must be in the same directory or |
  129.      |subdirectory                                                        |
  130.      |                                                                    |
  131.      |Type a name for the output files, without an extension.             |
  132.      |                                                                    |
  133.      |You may include a path and must include a name, e.g. A:\DATA\OUTFILE|
  134.      |where DATA is a subdirectory and OUTFILE is a file name.            |
  135.      |Do not include a "dot" or a 3 letter extension.                     |
  136.      |                                                                    |
  137.      |B:SAMPLE                                                            |
  138.      *====================================================================*
  139.  
  140.         If you saved the regression information of a previous session
  141.         with CFIT, this option allows you to retrieve it. The data file
  142.         and the two files created with the save command, a .REG file and
  143.         a .HDR file, should all be available in same path you specify as
  144.         part of the name for output files. The output file name does not
  145.         have to be the same as the data file name, but the data file
  146.         should have the same name as it did when the regressions were
  147.         originally run.
  148.              After either getting or running a regression, you will be
  149.         presented with the main menu shown above, except now you have
  150.         all choices available. The program will return to this menu
  151.         after every operation.  All of the menu selections will lead to
  152.         additional prompts. Two of the most common are
  153.  
  154.                     *=====================================*
  155.                     |                                     |
  156.                     |    Do you want the                  |
  157.                     |              O Original             |
  158.                     |        or    T Transformed data?    |
  159.                     |                                     |
  160.                     *=====================================*
  161.  
  162.  
  163.        *================================================================*
  164.        |                                                                |
  165.        |What is the regression number of the regression you want to use?|
  166.        |                                                                |
  167.        *================================================================*
  168.  
  169.              Original data is the data as it comes from the data file.
  170.         Transformed data is produced in fitting Y to any of the forms
  171.         used by CFIT except (1), described below.
  172.         The regression number is a number assigned by CFIT when it gen-
  173.         erates the regressions. It can be found by running Report Re-
  174.         gression Results. Run this option right after the regressions
  175.         are generated.
  176.  
  177.  
  178.         CFIT                                                       Page 4
  179.  
  180.         Crashing the System
  181.  
  182.              CFIT has built in error detection for most input and out-
  183.         put. There are only a few places where you need to be careful.
  184.             When running a regression for the first time, CFIT reads the
  185.         data file and counts the number of rows and columns. It does not
  186.         check each row to make sure that they all have the same number
  187.         of entries. If a row is short, CFIT could read beyond the end of
  188.         the file and crash.
  189.              If the data set contains more than 250 rows, strange things
  190.         could happen. The program will continue reading past the 250th
  191.         row using memory that is probably in use for something else. The
  192.         only remedy for this is not to do it. Changing the constant
  193.         MaxNumRow at the beginning of the source code will allow larger
  194.         data sets to be used. I have successfully run CFIT with as many
  195.         as 1225 rows of data.
  196.              If you get into something you want to get out of, some-
  197.         times you can do it. If you just enter a carriage return when
  198.         CFIT asks for a name, CFIT will abort what you are doing and
  199.         go back to the main menu after another carriage return. Other
  200.         times, you'll have to grin and bear with unwanted output.
  201.  
  202.         How CFIT Works
  203.  
  204.              This section is a bit technical. It might help to go to the
  205.         sample run and come back here when you have questions.
  206.              CFIT uses these forms:
  207.  
  208.                 F  =  0                                   (0)
  209.                 F  =  X                                   (1)
  210.                 F  =  X^2                                 (2)
  211.                 F  =  1 / X                               (3)
  212.                 F  =  1 / X^2                             (4)
  213.                 F  =  Ln ( X )                            (5)
  214.                 F  =  X * Ln ( X )                        (6)
  215.                 F  =  [ Ln ( X ) ] / X                    (7)
  216.  
  217.         to fit equations of the form
  218.  
  219.              YHAT  =  A  +  B1 X1  +  B2 X2               (8)
  220.  
  221.         using least squares. Y can use any of the forms (1) through (7).
  222.         Both X1 and X2 are transformations of the predictor variable X.
  223.          X1 can use any of the forms (1) through (7) and X2 can use (0)
  224.         through (6).  All choices of form are subject to restrictions.
  225.         No form is allowed if it cannot be computed for all data points.
  226.         if X contains one or more zeros, forms (3) through (7) cannot be
  227.         used for either X1 or X2. X cannot use forms (5), (6) or (7)
  228.         with negative data. These same restrictions apply to Y, as well
  229.         as two additional ones. In order to compute fitted Y values,
  230.         YHAT, from (8), Y must be a monotonic function of the right hand
  231.         side of (8). Forms (2), (4), (6) and (7) are not monotonic, so
  232.         additional restrictions must be placed on Y when using these
  233.         forms. To use (2) and (4) for Y, all observations must be larger
  234.         than 0. To use (6), all Y values must be larger than 1/e. For
  235.         (7), all y values must be larger than e. The forms are monotonic
  236.         over these ranges. 
  237.  
  238.  
  239.         CFIT                                                       Page 5
  240.  
  241.  
  242.              The program automatically checks these restrictions, as
  243.         well as one other. If X is dichotomous, for example if X can
  244.         only be 0 or 1, then X1 and X2 will be perfectly correlated
  245.         regardless of the forms chosen. The correlation between X1 and
  246.         X2 can be near 1 in other circumstances as well. If this hap-
  247.         pens, the model is not fitted.
  248.              The regressions generated by CFIT are sorted in two ways,
  249.         by F Ratio and by Adjusted Coefficient of Determination. Sorting
  250.         is done using a heap sort procedure (Scheid [1982]). The results
  251.         of the sorts are saved as linked lists.
  252.              CFIT is written modularly in Turbo Pascal. Variable and
  253.         procedure names were chosen to be as mnemonic as possible. Those
  254.         names that are not mnemonic, as well as most that are, follow
  255.         the notation of Snedecor and Cochran [1967]. To follow the pro-
  256.         gram logic, start reading in the menu procedure and follow the
  257.         flow from there. There are few commonly used diagnostic statis-
  258.         tics that CFIT does not already calculate.
  259.  
  260.         Sample Run
  261.  
  262.              The file SAMPLE.SDA is an SDA data file containing data
  263.         from Myers et al [1959, page 305]. This is failure data for a
  264.         reliability test in which 17 of the items on test ultimately
  265.         failed. Column 1 contains the failure times, in thousands of
  266.         of hours, and column 2 contains the estimated reliability. The
  267.         purpose of running CFIT with this data is to establish a model
  268.         for estimated reliability, Y, as a function of time, X.
  269.         SAMPLE.OUT has CFIT output for this data. Type this file to
  270.         printer to follow the discussion.
  271.              The Report Regression Results output is shown on page 1.
  272.         To generate this output, I specified "Sort by F Ratio" and
  273.         "Print 10 Regressions" in response to prompts. In the output,
  274.         CFIT prints a three line header summarizing the run. It tells us
  275.         168 regressions were run. 38 that might have been run were not
  276.         because one or more constraints were violated. The table shows
  277.         summary information about the 10 best regressions sorted by F
  278.         ratio and the 168th, the worst regression. The second column
  279.         shows regression numbers, which you need to tell CFIT which
  280.         regression to work with. The next three columns identify the
  281.         transformations used on Y, X1 and X2.  These numbers are the
  282.         ones used in the "How CFIT works"section. As an example of using
  283.         these, look at the first regression reported, number 158. Both
  284.         Y and X1 use form 6 and X2 uses form 2. Putting these forms to-
  285.         gether with the coefficients shown in the A, B1 and B2 columns,
  286.         the regression equation is
  287.  
  288.          YHAT * Ln(YHAT)  =  .0437 + .1730 * X * Ln(X) - .0172 * X^2 .
  289.  
  290.         This equation cannot be put in the form Y = f(X). The C and F
  291.         options in the main menu are there to handle results like this.
  292.         Read the discussion of the table of residuals output for more
  293.         information.
  294.              The last columns in the Report Regression Results table
  295.         show the residual degrees of freedom, the F value, the coeffi-
  296.         cient of determination, R^2, the adjusted coefficient of deter-
  297.         mination, RBAR^2 , and the standard error of estimate. 
  298.  
  299.  
  300.         CFIT                                                     Page 6
  301.  
  302.  
  303.              The Print Details of a Fit output for regression 158
  304.         is also shown on page 1. The ANOVA table shows the regression
  305.         sum of squares partitioned in both possible ways. Following
  306.         this, a table shows the regression coefficients, beta coeffi-
  307.         cients, standard deviations of the regression coefficients and
  308.         Student's T ratios for the regression coefficients. Next, the
  309.         correlation between X1 and X2 is printed. Here, at -.9969, it is
  310.         high enough to cause some concern. Looking at alternative re-
  311.         gressions, like 143 or 153, might find one with a lower correla-
  312.         tion between predictors.
  313.              Finally, the values of C11, C22 and C12 are reported. These
  314.         values are needed to compute SMuHat, which we will do below.
  315.              Page 2 shows a histogram and table of residuals. Ideally,
  316.         the histogram of residuals in transformed units, as shown,
  317.         should be symmetric about the zero cell, bell shaped, with only
  318.         about 6% of the observations in the tail cells.
  319.              The table of residuals gives information necessary for
  320.         writing Student's T based confidence intervals. We go through
  321.         one example here. The data in SAMPLE.SDA is
  322.  
  323.                 Row     Failure Time ( X )     Reliability ( Y )
  324.                  1            1.187                  .980
  325.                  2            2.397                  .959
  326.                  3            2.564                  .938
  327.                  4            3.024                  .917
  328.                  5            3.364                  .895
  329.                  .              .                     .
  330.                  .              .                     .
  331.                  .              .                     .
  332.  
  333.              Suppose we want a 90% confidence interval for the relia-
  334.         bility of the system at X = 2,564 hours. This is the value of X
  335.         in the third row of data, so we use the third row of the resid-
  336.         uals table to find YHAT = -.04088217 and  SMuHat = .0043426339.
  337.         From the top row of output, we find SEE = .01021524, and use
  338.         this to calculate SYHat,
  339.  
  340.             SYHat  =  ( SMuHat^2   +  SEE^2  )^.5     =   .0111000.
  341.  
  342.         Finally, we need the 95th percentile of the Student's T distri-
  343.         bution with 14 degrees of freedom. This can be found in the T
  344.         table of many statistics texts, or we can compute it using TINV,
  345.         a program supplied with CFIT for doing just this. Running TINV
  346.         and specifying DF = 14 and Prob = .95, TINV reports Percentile
  347.         as 1.763. The confidence interval is the interval from
  348.         YHAT - SYHat * Percentile to  YHAT + SYHat * Percentile.
  349.         Performing the calculations, we get -.0605 and  -.0213.
  350.         These are confidence limits for the transformed Y. To get limits
  351.         for Y in the original units, we need to invert the transforma-
  352.         tion. This is where menu option F comes in. Select option F with
  353.         regression 158 and respond to the prompt with -.0605. CFIT
  354.         reports back .9375 for Y in Orig Units. Doing the same with
  355.         -.0213, CFIT gives us .9785. So we are 95% confident that the
  356.         system reliability at 2,564 hours is between .9375 and .9785.
  357.  
  358.  
  359.         CFIT                                                       Page 7
  360.  
  361.  
  362.              If we needed to do this computation for a value of X that
  363.         was not part of the original data, we would use menu option C to
  364.         compute YHAT. This option will also give SMuHat with transformed 
  365.         data. Alternatively, SMuHat can be computed by hand using the
  366.         formula
  367.  
  368.          SMuHat^2 = SEE^2 ( 1/n + C11*X1^2 + C22*X2^2 + 2*C12*X1*X2 ).
  369.  
  370.         C11, C22 and C12  are given by Print Details of a Fit.
  371.  
  372.              The third page of SAMPLE.OUT shows a plot of regression 158
  373.         and the original data. The regression equation is plotted with
  374.         asterisks and the original data with zeros. If * and 0 occur at
  375.         the same plot position, the 0 is printed. Multiple observations
  376.         at the same plot position are plotted with the numbers 2 through
  377.         9. A number sign, #, indicates that 10 or more observations are
  378.         plotted at the same position.
  379.              In the plot shown, notice that the fitted curve flattens
  380.         out abruptly at .37. This is because form 6, used for Y here,
  381.         truncates at 1/e, about .37. Since Y is reliability, a number
  382.         between 0 and 1, form 6 is probably inappropriate. We may want
  383.         to look at regressions 46, 31, 41 or 18, reported on page 1, for
  384.         alternate models.
  385.  
  386.         Recompiling CFIT
  387.  
  388.              If you recompile CFIT to increase maximum sample size or
  389.         change printer codes, be sure to give the appropriate value to
  390.         the constant TurboType. If you use Turbo Pascal, TurboType
  391.         should be 88. If you use Turbo-87, set TurboType to 87.
  392.  
  393.         List of References
  394.  
  395.         Myers, R. H., H. I. Dwyer, B. P. Goldsmith, R. L. McLaughlin
  396.         and J. D. Stevenson. 1959. Production and Field Reliability.
  397.         Electronics Division of the American Society for Quality
  398.         Control. Milwaukee.
  399.  
  400.         Scheid, Francis. 1982. Computers and Programming. Schaum's Out-
  401.         line Series in Computers. McGraw - Hill. New York.
  402.  
  403.         Snedecor, George W. and William G. Cochran. 1967. Statistical
  404.         Methods, sixth edition. Iowa State University Press. Ames, Iowa.
  405.  
  406.         The Bottom Line
  407.  
  408.              I believe in a statement that appeared in a computer mag-
  409.         azine recently, that no user values any software above $4.95.
  410.         That's what I am asking for CFIT. (Gimme a break, lets make it
  411.         5 bucks). This won't make me rich or you poor, but if a enough
  412.         people think CFIT is worth $5 a copy, it will encourage me to
  413.         continue distributing programs this way.
  414.              So that's it. If you try CFIT and find it useful, please
  415.         pay $5.00 for each actively used copy. An invoice follows for
  416.         your convenience.
  417.  
  418.  
  419.  
  420.  
  421.                                   CFIT INVOICE
  422.  
  423.  
  424.  
  425.  
  426.         Make checks Payable to  Joseph C. Hudson
  427.                                 4198 Warbler Dr.
  428.                                 Flint, MI 48504
  429.  
  430.  
  431.  
  432.  
  433.  
  434.         Quantity           Item                          Total
  435.  
  436.         ________           Copies of CFIT @ $5 each      ______________
  437.  
  438.  
  439.         Name and address of sender:
  440.  
  441.  
  442.         ____________________________________________
  443.  
  444.  
  445.         ____________________________________________
  446.  
  447.  
  448.         ____________________________________________
  449.  
  450.  
  451.  
  452.         Your comments and suggestions are appreciated. Thanks for your
  453.         support.
  454.