"I am a psychiatric geneticist but my degree is in neuroscience, which means that I now do far more statistics than I have been trained for. I cannot overstate to you the magnitude of the change in my productivity since finding this book. Even after reading the first few chapters, which explain why data analysis is painful and how one can implement a long-term solution, my research moved forward greatly."--Amber Baum, National Institute of Mental Health
"I enjoyed reading this book and learned a great deal from it. Modeling with Data filled in a lot of holes in my knowledge, and I think that will be true in general for other readers as well. There is a lot of high-quality and interesting material here."--Brendan Halpin, University of Limerick
About the Author
Ben Klemens is a senior statistician at the National Institute of Mental Health. He is also a guest scholar at the Center on Social and Economic Dynamics at the Brookings Institution.
Excerpt. © Reprinted by permission. All rights reserved.
Modeling with Data
Tools and Techniques for Scientific ComputingBy Ben Klemens
PRINCETON UNIVERSITY PRESS
Copyright © 2009 Princeton University Press
All right reserved.
ISBN: 978-0-691-13314-0
Contents
Preface.....................................................................xiChapter 1. Statistics in the modern day.....................................1PART I COMPUTING...........................................................15Chapter 2. C................................................................172.1 Lines...................................................................182.2 Variables and their declarations........................................282.3 Functions...............................................................342.4 The debugger............................................................432.5 Compiling and running...................................................482.6 Pointers................................................................532.7 Arrays and other pointer tricks.........................................592.8 Strings.................................................................652.9 [??] Errors.............................................................69Chapter 3. Databases........................................................743.1 Basic queries...........................................................763.2 [??] Doing more with queries............................................803.3 Joins and subqueries....................................................873.4 On database design......................................................943.5 Folding queries into C code.............................................983.6 Maddening details.......................................................1033.7 Some examples...........................................................108Chapter 4. Matrices and models..............................................1134.1 The GSL's matrices and vectors..........................................1144.2 apop_data...............................................................1204.3 Shunting data...........................................................1234.4 Linear algebra..........................................................1294.5 Numbers.................................................................1354.6 [??] gsl_matrix and gsl_vector internals................................1404.7 Models..................................................................143Chapter 5. Graphics.........................................................1575.1 plot....................................................................1605.2 [??] Some common settings...............................................1635.3 From arrays to plots....................................................1665.4 A sampling of special plots.............................................1715.5 Animation...............................................................1775.6 On producing good plots.................................................1805.7 [??] Graphs-nodes and flowcharts........................................1825.8 [??] Printing and LATEX.................................................185Chapter 6. [??] More coding tools...........................................1896.1 Function pointers.......................................................1906.2 Data structures.........................................................1936.3 Parameters..............................................................2036.4 [??] Syntactic sugar....................................................2106.5 More tools..............................................................214PART II STATISTICS.........................................................217Chapter 7. Distributions for description....................................2197.1 Moments.................................................................2197.2 Sample distributions....................................................2357.3 Using the sample distributions..........................................2527.4 Non-parametric description..............................................261Chapter 8. Linear projections...............................................2648.1 [??] Principal component analysis.......................................2658.2 OLS and friends.........................................................2708.3 Discrete variables......................................................2808.4 Multilevel modeling.....................................................288Chapter 9. Hypothesis testing with the CLT..................................2959.1 The Central Limit Theorem...............................................2979.2 Meet the Gaussian family................................................3019.3 Testing a hypothesis....................................................3079.4 ANOVA...................................................................3129.5 Regression..............................................................3159.6 Goodness of fit.........................................................319Chapter 10. Maximum likelihood estimation...................................32510.1 Log likelihood and friends.............................................32610.2 Description: Maximum likelihood estimators.............................33710.3 Missing data...........................................................34510.4 Testing with likelihoods...............................................348Chapter 11. Monte Carlo.....................................................35611.1 Random number generation...............................................35711.2 Description: Finding statistics for a distribution.....................36411.3 Inference: Finding statistics for a parameter..........................36711.4 Drawing a distribution.................................................37111.5 Non-parametric testing.................................................375Appendix A: Environments and makefiles......................................381A.1 Environment variables...................................................381A.2 Paths...................................................................385A.3 Make....................................................................387Appendix B: Text processing.................................................392B.1 Shell scripts...........................................................393B.2 Some tools for scripting................................................398B.3 Regular expressions.....................................................403B.4 Adding and deleting.....................................................413B.5 More examples...........................................................415Appendix C: Glossary........................................................419Bibliography................................................................435Index.......................................................................443
Chapter One
Statistics in the modern day
Retake the falling snow: each drifting flake Shapeless and slow, unsteady and opaque, A dull dark white against the day's pale white And abstract larches in the neutral light. -Nabokov (1962, lines 13-16)
Statistical analysis has two goals, which directly conflict. The first is to find patterns in static: given the infinite number of variables that one could observe, how can one discover the relations and patterns that make human sense? The second goal is a fight against apophenia, the human tendency to invent patterns in random...