Statistical analyses and computer programming in personality A chapter for the Cambridge University Press Handbook of Personality Psychology

The use of open source software for statistical analysis provides personality researchers new tools for exploring large scale data sets and allows developing and testing new psychological theories. We review the development of these techniques and consider some of the major data analytic strategies. We provide example code for doing these analyses in R. contact: William Revelle revelle@northwestern.edu We greatly appreciate the thoughtful comments from David Condon. This is the final version as submitted to CUP. The official version is at The Cambridge Handbook of Personality Psychology, pp. 495-534. DOI: https://doi.org/10.1017/9781108264822.045. Published 18 September 2020. STATISTICAL ANALYSIS 2 Prologue: A brief history of Open Source Statistical Software It is hard to imagine early in the 21st century that many of the statistical techniques we think of as modern statistics were developed in the late 19th and early 20th centuries. What we now call regression was the degree of “reversion to mediocrity” as introduced by Francis Galton (1886). A refinement of regression was the measure of “co-relations” (Galton, 1888) which was specified as the relationship of deviations as expressed in units of the probable error. Galton’s insight of standardization of units became known as ‘Galton’s coefficient’ which, when elaborated by Pearson (1895,8,9) became what we now know as the Pearson Product Moment Coefficient. Because the Pearson derivations were seen as too complicated for psychologists, Charles Spearman (1904b) explained the developments of Pearson and his associates to psychologists where “the meaning and working of the various formulae have been explained sufficiently, it is hoped, to render them readily usable even by those whose knowledge of mathematics is elementary” (p 73 Spearman, 1904b). Later in that same paper, he then developed reliability theory and the correction for attenuation. In his second amazing publication that year he developed the basic principles of factor analysis and laid out his theory of general intelligence (Spearman, 1904a). Fundamental theorems of factor analysis (Thurstone, 1933; Eckart and Young, 1936) and estimates of reliability (Brown, 1910; Spearman, 1910; Kuder and Richardson, 1937; Guttman, 1945) came soon after and were all developed when computation was done by “computers” who were humans operating desk calculators. If not difficult, computation was tedious in that it required repeatedly finding sums of squares and sums of cross products. When examining the correlation structure of multiple items, the number of correlations went up by the square of the number of items, and thus so did the computational load. Test theory as developed in the 1930s and 1940s led to a number of convenient short cuts by which the sums of test and item variances could be used to estimate what the correlations of composites of items would be if certain assumptions were met. Thus, the coefficients of Cronbach (1951); Guttman (1945); Kuder and Richardson (1937) (α, λ3 and KR20) were meant to be estimates based upon the structure of covariances without actually finding the covariances. Another short cut was to dichotomize continuous data in order to find correlations. For example, in an ambitious factor analysis of individual differences in behavior among psychiatric patients (Eysenck, 1944) made use of this shortcut by dichotomizing continuous variables and then finding the Yule (1912) coefficient. Unfortunately, such a procedure produced a non-positive definite matrix which makes reanalysis somewhat complicated. With the need to calculate flight paths for large artillery shells and rockets, the ideas developed by Babbage for his “Analytical Engine” in 1838 (Bromley, 1982) and algorithms for programming (Lovelace, 1842) were converted from punched cards and automatic looms into the electrical tubes and circuit boards of von Neuman (Isaacson, 2014). The age of computation had arrived. It was now possible to properly analyze covariance structures. For personality psychologists, these were exciting times, for it allowed for the calSTATISTICAL ANALYSIS 3 culation of larger correlation matrices and the use of factor analysis with more elegant algorithms than the centroid approach. Indeed, Raymond Cattell moved from Harvard to the University of Illiinois because he was promised access to the new ‘ILLIAC’ computer (and would not have to teach undergraduates). Main frame computers and proprietary software At first, software for these new devices was tailor made for the particular machine, and there was a plethora of programming languages and operating systems. In the late 1950s the programming language FORTRAN (later renamed to be Fortran when computers learned about lower case) was developed at IBM for the numeric computation necessary for scientific computing and then translated for other operating systems. While some programs would run on IBM 709 and 7090s, others would only work on the super computers of the time, the Control Data Corporation’s 1604 and 6400. An early package of statistical programs, developed for the IBM 7090 in 1961 at UCLA was the BioMedical Package (BMDP). At first BMDP was distributed for free to other universities but BMDP (Dixon and Brown, 1979) eventually became a commercial package which has since disappeared. Two other statistical systems (SAS R © and SPSS), originally developed at other universities (North Carolina State and Stanford) and shared with others, were also developed. These three major software systems for doing statistics came from three somewhat different traditions. BMDP was developed for biomedical research, SAS R © for agriculture research, and SPSS for statistics in the social sciences (SPSS, 2008). Although all three systems were originally developed at universities and were freely distributed to colleagues, all three soon became incorporated as for profit corporations. All were developed for main frame computers where instructions were originally given in stacks of Hollerith Cards (known to many as IBM cards), containing 80 characters per card. All of the programs made use of the FORTRAN programming language and still, many years later, have some of their main frame geneaology embedded in their systems. Older researchers still shudder at the memories of needing to wait for 24 hours after turning in a box of cards only to discover one typo negated the entire exercise. S and R: interactive statistics In contrast to the statistical analyses done on mainframes, S and subsequently R were developed for interactive statistics. The S computing ‘environment’ was developed for Unix in the 1970’s at Bell labs by John Chambers and his associates (Becker, Chambers, and Wilks, 1988). It was meant to take advantage of interactive computing where the user could work with his/her data to better display it and understand it. After several iterations it became the defacto statistical package for those using the Unix operating system. In 1992, two statisticians, Ross Ihaka and Robert Gentleman, at the University of Otago, in New Zealand started adapting S to run on their Mac computers. It incorporated the list oriented language Scheme and emphasized object-oriented programming. Most importantly, they STATISTICAL ANALYSIS 4 shared the design specifications with other interested developers around the world and intentionally did not copyright the code. Rather, they, with the help of John Chambers and the rest of the R Development Core Team, deliberately licensed R under the GNU General Public License of the Free Software Foundation which allows users to copy, use, and modify the code as long as the product remains under the GPL (R Core Team, 2018). Perhaps the real power of R is that because it is open source, it is extensible. That means that anyone can contribute packages to the overall system. That, and the power of the GPL and open source software movement has led to an amazing effect. From the original functions in R and the ones written by the R Core Team, more than 12,600 packages have been contributed to the CRAN, the Comprehensive R Archive Network, and at least (as of this writing) more than 34,000 packages are available on GitHub. R has become the lingua franca of statistics and many new developments in psychological statistics are released as R functions or packages. When writing methodology chapters or articles, the associated R code to do the operations may also be given (as we do in this chapter). With the growing recognition of the importance of replicable research, the publication of the R scripts and functions to do the analysis, as well as the release of R readable data sets is an essential step in allowing others to understand and repeat what we have done. Because the source code of all of the R packages is available, users can check the accuracy of the code and report bugs to the developers of the particular package. This is the ultimate peer review system, in that users use, review, and add to the entire code. Given its open source nature and growing importance in scientific computing, much of the rest of this chapter will be devoted to discussing how particular analyses can be done in R. This is not to deny that commercial packages exist, but to encourage the readers of this handbook to adopt modern statistics. The actual code used for the tables and figures is included in the Appendix. Finally, little appreciated by many users of R is that it is not just a statistical environment, it is also a very high level programing language. Although some of the packages in R are written in Fortran or C++, many packages are written in R itself. R allows operations at the higher matrix level and allows for object-oriented programming. Each function operates on ‘objects’ and returns another ‘object’. That is, functions can be chained together to add value to previous operations. This allows users to include standard functions in their own functions with the output a