<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title> </title>
    <link>http://pealco.net/code</link>
    <language>en</language>
    <webMaster>pealco@gmail.com (Pedro Alcocer)</webMaster>
    <copyright>Copyright 2007-2008</copyright>
    <ttl>60</ttl>
    <pubDate>Sun, 24 Aug 2008 13:07:00 GMT</pubDate>
    <description></description>
    <item>
      <title>Repeated measures ANOVA in R</title>
      <link>http://pealco.net/code/past/2008/8/24/repeated_measures_anova_in_r/</link>
      <pubDate>Sun, 24 Aug 2008 12:46:00 GMT</pubDate>
      <guid>http://pealco.net/code/past/2008/8/24/repeated_measures_anova_in_r/</guid>
      <author>pealco@gmail.com (Pedro)</author>
      <description>&lt;p&gt;Repeated measures ANOVAs in R are performed with the &lt;code&gt;aov()&lt;/code&gt; function. The &lt;code&gt;aov()&lt;/code&gt; function requires fully balanced data to work correctly, i.e., there can be no missing values in the data. In order to use &lt;code&gt;aov()&lt;/code&gt; on data with missing values (most experimental data has excluded values), one needs to average over subjects or items.&lt;/p&gt;

&lt;p&gt;Below, we assume a data frame &lt;code&gt;data&lt;/code&gt; with at least the columns &lt;code&gt;subject&lt;/code&gt;, &lt;code&gt;factor1&lt;/code&gt;, &lt;code&gt;factor2&lt;/code&gt;, and &lt;code&gt;logRT&lt;/code&gt;. The code below averages over subjects, returning the data frame &lt;code&gt;data.subject&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;
data.subject = aggregate(data$logRT, list(data$subject, data$factor1, data$factor2), mean)
colnames(data.subject) = c("subject", "factor1", "factor2", "logRT")
&lt;/pre&gt;

&lt;p&gt;An alternative is to use the excellent &lt;code&gt;reshape&lt;/code&gt; package.&lt;/p&gt;

&lt;pre&gt;
library(reshape)
data.subject = recast(data, SUBJ + factor1 + factor2 ~ variable, mean, measure.var="logRT")
&lt;/pre&gt;

&lt;p&gt;You can then perform the repeated measures ANOVA on &lt;code&gt;data.subject&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;
summary(aov(logRT ~ factor1 * factor2 + Error(subject/(factor1 * factor2)), data=data.subject))
&lt;/pre&gt;</description>
      <category domain="http://pealco.net/code/past/tags/ANOVA">ANOVA</category>
      <category domain="http://pealco.net/code/past/tags/R">R</category>
    </item>
    <item>
      <title>Linger-process: Really easy Linger data pre-processing in Ruby</title>
      <link>http://pealco.net/code/past/2008/8/23/really_easy_linger_data_preprocessing/</link>
      <pubDate>Sat, 23 Aug 2008 19:05:00 GMT</pubDate>
      <guid>http://pealco.net/code/past/2008/8/23/really_easy_linger_data_preprocessing/</guid>
      <author>pealco@gmail.com (Pedro)</author>
      <description>&lt;p&gt;This is a set of Ruby classes for processing data output from Doug Rohde's &lt;a href="http://tedlab.mit.edu/~dr/Linger/"&gt;Linger&lt;/a&gt; software for self-paced reading experiments.&lt;/p&gt;

&lt;p&gt;Simply stated, it takes &lt;a href="http://github.com/pealco/linger-process/tree/master%2Fexample-input-data%2F1.dat?raw=true"&gt;raw Linger output&lt;/a&gt; and turns it into &lt;a href="http://github.com/pealco/linger-process/tree/master%2Fexample-output-data.txt?raw=true"&gt;a table&lt;/a&gt; for use in R.&lt;/p&gt;

&lt;p&gt;The latest working version is available from &lt;a href="http://github.com/pealco/linger-process/"&gt;github&lt;/a&gt;. A usage example is below.&lt;/p&gt;

&lt;pre name="code" class="ruby"&gt;
require "linger-process.rb"

# A new Experiment object takes four arguments, two of which are required:  
#   (1) required, Array that specifies the names of the experiment(s)  
#   (2) required, Hash that specifies how the conditions should be expanded  
#   (3) optional, String that specifies the directory containing the Linger data,  
#       defaults to "./data/"  
#   (4) optional, Array of symbols that specifies what columns should be output,  
#       defaults to  
#       [:words, :word_lengths, :word_positions, :regions, :experiment, :subject,    
#        :item, :condition, :sentence_number, :list_position, :reading_times,  
#        :log_reading_times, :accuracy]


experiment_names = ["principB", "principC"]

# Here, for example, the condition coded as TNN in the raw data is
# expanded out to the factors RC, N, and U. You can specify as many
# conditions and factors as necessary.

factors = { "TNN" =&gt; %w(RC N U),
            "TNM" =&gt; %w(RC M U),
            "QNN" =&gt; %w(HN N U),
            "QMN" =&gt; %w(HN M G)}

data_directory = "./example-input-data/"

columns = [:experiment, :subject, :item, :condition, :factors, :regions, 
           :reading_times, :log_reading_times, :words, :word_lengths, 
           :word_positions, :list_position, :accuracy]

experiment = Experiment.new(experiment_names, factors, data_directory, columns)

# All processing is done within the object. There are two 
# options for outputting the processed data. You can either output
# it to STD_OUT (to check that everything went smoothly), or you can
# save it to a file.

#puts experiment                              # to STDOUT
experiment.to_file("example-output-data.txt") # to a file
&lt;/pre&gt;</description>
      <category domain="http://pealco.net/code/past/tags/linger">linger</category>
      <category domain="http://pealco.net/code/past/tags/ruby">ruby</category>
    </item>
    <item>
      <title>Calculating d-prime in R</title>
      <link>http://pealco.net/code/past/2008/8/23/calculating_dprime_in_r/</link>
      <pubDate>Sat, 23 Aug 2008 19:04:00 GMT</pubDate>
      <guid>http://pealco.net/code/past/2008/8/23/calculating_dprime_in_r/</guid>
      <author>pealco@gmail.com (Pedro)</author>
      <description>&lt;p&gt;This function takes a data frame &lt;code&gt;data.frame&lt;/code&gt; and returns a &lt;a href="http://en.wikipedia.org/wiki/D_prime"&gt;d-prime score&lt;/a&gt; for each unique entry in the &lt;code&gt;subject&lt;/code&gt; column of the data frame. Note that the function will return &lt;code&gt;Inf&lt;/code&gt; or &lt;code&gt;-Inf&lt;/code&gt; if any value in &lt;code&gt;Hrate&lt;/code&gt; or &lt;code&gt;Frate&lt;/code&gt; is 1 or 0.&lt;/p&gt;

&lt;pre name="code" class="ruby"&gt;
dprime = function(data.frame) {
    yes         = subset(data.frame, resp=="Y")
    no          = subset(data.frame, resp=="N")
    hit         = subset(data.frame, resp=="Y" &amp; acc == 1)
    falsealarm  = subset(data.frame, resp=="N" &amp; acc == 0)

    Hrate = xtabs(~subject,data=hit)/xtabs(~subject,data=yes)
    Frate = xtabs(~subject,data=falsealarm)/xtabs(~subject,data=no)
    dprime_score = qnorm(Hrate) - qnorm(Frate)

    return(dprime_score)
}
&lt;/pre&gt;</description>
      <category domain="http://pealco.net/code/past/tags/R">R</category>
    </item>
  </channel>
</rss>
