# Updated March 4, 2006 # R code for running the analyses in # "An Experiment in Minimalist Experimental Syntax" # using GLMM (generalized linear mixed modeling). # This code can simply be copied and pasted into R # ("#" marks comment lines ignored by R). # ********************** # ** IMPORTANT! ** # ********************** # Start by using "Change dir..." in R's "File" menu # to change the directory to where you saved the data file! # Otherwise you'll have to type in the whole path, which is a pain. # The GLMM analysis uses R's lme4 package (written by Douglas Bates). # If this is your first time using the lme4 package, you need to # install it. Use "Install package(s)..." in R's "Packages" menu # to find the source nearest you, or simply run the following command: install.packages("lme4") # After installing it, you need to load it. # You can do this by using "Load package..." in R's "Packages" menu, # or you can run the following command. Note that the lme4 package (actually, # the prerequisite package "Matrix") is very large, so it takes a little # while to load (about 30 seconds on my machine). So don't panic if your # computer seems to freeze at this point! This preinstallation helps the # package run faster when actually used. library(lme4) # Note that you need to load lme4 this every time you start R # (assuming you want to use lme4 again). # R is an open-source project, so it is frequently updated. # To check if the package has been updated since the last time you # installed it, use "Update packages..." in R's "Packages" menu, or # the run the command "update.packages()". # The lme4 command used here to conduct GLMM is called "lmer", # for "linear mixed-effect ... something." Maybe that's an agentive suffix? # To see R's help page on lmer, you can use "R functions (text)..." # in R's "Help" menu, or enter the following command (without "#"): # help("lmer") # The syntax of lmer is like this: # lmer(Y ~ X... + (1|S), data = D, family = "F", method = "M") # Y = output variable # X... = formula for input variables # (For example, if there are two input variables X1 and X2 # and you want to check their interaction, you would use X1*X2 # but if you don't care about their interaction, you would use X1+X2.) # S = subject. The (1|S) syntax makes R group data by subjects, and treats # subjects as random. By contrast, the X... variables are "fixed". # GLMM uses both random and fixed variables so it's "mixed". # D = name of data source (see below) # F = name of statistical distribution family. # (Since our data are binary, we need the "binomial" family.) # M = method for estimating GLMM, since GLMM can't be computed exactly. # (Note that the analyses here use the "Laplace" method, which is the # best method currently available with the lmer function, # as of March 4, 2006. If you don't specify the method, lmer uses # the slightly faster but somewhat less accurate "PQL" method by default.) # OK, let's start! # Load the data file and give it a name # (any name is OK if you're consistent): minexp = read.table("minexp.txt",T) # Allow R to identify columns by their headers: attach(minexp) # First analysis (ignoring order): lmer(Judgment ~ Topic*Adjunct + (1|Speaker), data = minexp, family = "binomial", method = "Laplace") # Second analysis (testing satiation in main factors): lmer(Judgment ~ Order*Topic + Order*Adjunct + (1|Speaker), data = minexp, family = "binomial", method = "Laplace") #Third analysis (removing nonsignificant interactions): lmer(Judgment ~ Topic + Order*Adjunct + (1|Speaker), data = minexp, family = "binomial", method = "Laplace") # The above output, the key results are listed in the "Fixed effects" # tables. The sign of each "Estimate" shows the direction of the effect, # and the p-value ("Pr(>|z|)") indicates significance. The stars help # to make the significance patterns visually clear. # If you want to know how I did the reanalyses using subsets of speakers, # contact me; the code I used is too ugly to distribute yet!