University of North Texas



Datasets and Code

Like many psychology students of recent times I was brought up in point-and-click style, patting myself on the back whenever output magically appeared and pretending I knew what I was talking about with regard to such legerdemain.  What I came to learn was that simply getting output is something wholly different than doing statistical analysis, and that to do a good analysis requires getting one's hands dirty.

However, I also don't think it's necessary to become a computer programmer outright (or at least shouldn't be).  One can take what is necessary and use it in an applied fashion, doing much better analyses and more efficient ones.  As such code is provided for lab content below so that you can spend more time on understanding the analysis, with some additional stuff for R, my preferred stat program.  The SAS will not be great as it is my preference to not use it if I can help it.  I find I like it as a program better than SPSS in terms of what it can do, but just about everything regarding it is 'ugly' in appearance.  Neither syntax is as flexible as R, and almost always requires much more code to do the same thing.  Also, if you come across a more efficient way to do something definitely let me know and I'll put it up here.  For lab specific code click here.

Link breakdown

Purpose: General statement on what's going on, things to look out for etc.

Stat program name: the page with all the code

Marks within cells: specific code relevant to purpose

Code relevant to labs


Entering Data X X X
Importing Data X X X
Manipulating Data X X  
Frequencies X X X
Central Tendency and Variability X X X
Summary Statistics X X X
t-tests X X  
Correlation X X X
Simple Regression X X  
Power and Effect Size X N/A  


Most datasets used in class and lab demonstration may now be accessed here. Text files automatically load into the browser, just access and save when you see it on your screen.  For SPSS files, download when the dialog box presents itself to.  Note that by default Rcmdr imports the factor labels (i.e. the words rather than the numbers if there is a choice).  If you prefer them or need them to stay numeric, uncheck that box that says 'convert value labels to factor levels' during the import process.
Howell datasets.
Karl Wuensch's datasets.

Useful R packages/functions

Pdf for installing R at home
Quick R: an R website  for SAS/SPSS/Stata Users R wiki
R web interface and notes
Using R in Psychological Research
ANOVA and Regression in R (book)
R graphics R colors
R for SAS and SPSS Users
Comparing those three packages
Cran Task Views
Wilcox, Workshop
Fox, Robust appendix
General regression related functions
Robust regression functions
BMA: Bayesian model averaging
Boot, simpleboot: basic bootstrap
Design: useful functions for anova/regression, validation
Hmisc: general purpose
lme4 and nlme: mixed effects/multilevel modeling
ltm: Item response theory
MASS: evolved from Venerable and Ripley's Modern Applied Statistical Analysis
MBESS: Behavioral Sciences specific, tons of effect size goodies
Mike's Miscellaneous
Multtest: multiple comparisons in ANOVA
prettyR: make descriptive output 'pretty'
Psy: psychometric stuff
Psych: includes functions for personality and psychological research
QuantPsyc: for testing moderation and mediation
Quantreg: quantile regression
R-commander: menu system
Relaimpo: measures relative importance of variables in multiple regression in a meaningful way
Robust library that makes it easy, notes
Robustbase: more robust regression
sem: structural equation modeling
Wilcox library (a host of robust functionality)
For Mike Miscellaneous and Wilcox libraries, right click and save them in your main R folder, and whenever you want to use the functions within, from the menu File/Source R code, then go find your file. Or at the command line
Where the quotes have the address of the file location.  To see what's in them just open them up like any other script. See the Wilcox link for more info.  With the Mike misc, Macs may have an issue sourcing the file, but if you just cut and paste the functions (just click the link rather than save) at the console that will work until I can figure out the issue.  Help file for projects
General psych/social science-related stuff in R
Psychometrics: IRT, SEM etc.
Social Science: general

Some examples of code I find useful:

Cohen's d, R2, Intervals for them
Plotting Cohen's d
False Discovery Rate
Whizbang intervals
Robust correlation and simple regression
Bootstrap t-test (requires Wilcox libraries above)
Robust regression (general)
Simple Mediation
Testing multivariate normality
All subsets regression: note that it is better accomplished in the R-commander menu system if you install the Rcmdr.HH library (see above).  You even get a nice graphic.
Validation of a linear model
Path analysis of lecture notes example
Creating a dataset
Plotting interactions in regression


Simple effects SPSS syntax
R, S-Plus, SAS and SPSS scripts for CIs for effect sizes (Smithson)