Beauchamp:CIMS: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
== Causal Inference of Multisensory Speech Model ==
== Causal Inference of Multisensory Speech Model ==
''NB'': This code is in active development
''NB'': This code is in active development


'''A copy of this help manual is included in the code pack as README.txt'''
'''A copy of this help file is included in the code pack as README.txt'''


If you run into trouble with any step, please contact me: john dot magnotti at gmail dot com. If the model fitting fails to converge for your dataset, you may need to send me at least a portion of the data so I can replicate the error.
If you run into trouble with any step, please contact me: john dot magnotti at gmail dot com. If the model fitting fails to converge for your dataset, you may need to send me at least a portion of the data so I can replicate the error.
Line 28: Line 27:
We need to ensure R can find the data and code files
We need to ensure R can find the data and code files
# Launch R
# Launch R
# Open the file fit_models.R:  File-> Open Document  
# Open the file '''fit_models.R''':  File-> Open Document  
# We need to make 4 changes to before running the code. See the comments in the code file for additional direction
# We need to make 4 changes before running the code. See the comments in the code file for additional direction
## Line 5: Set the path to be the location of the downloaded files. If you extracted the code pack to your desktop, the path may already be correct
## Line 5: Set the path to be the location of the downloaded files. If you extracted the code pack to your desktop, the path may already be correct
## Line 11: Set the location of the data to be fit
## Line 11: Set the location of the data to be fit
## Line 14: Set the value of max_count to be the total number of trials at each asynchrony for each condition.  
## Line 14: Set the value of '''max_count''' to be the total number of trials at each asynchrony for each condition.  
## Line 17: Set the value of the asynchronies used in each condition. The order of the asynchronies must match the order in the data file. For multiple condition experiments, list the asynchronies only once.
## Line 17: Set the value of the '''asynchronies''' used in each condition. The order of the asynchronies must match the order in the data file. For multiple condition experiments, list the asynchronies only once.
# Run the setup code to make sure there are no errors
# Run the setup code to make sure there are no errors
## Highlight lines 1 through 17 using the mouse
## Highlight lines 1 through 17 using the mouse
Line 39: Line 38:


'''Fitting the model'''
'''Fitting the model'''
# Highlight and execute Line 31 to build worker threads
 
<code>cl = makeCluster(detectCores())</code>
Highlight and execute each of the following lines in turn
# Highlight and execute the code to fit the CIMS model to the data. This step can take a while
<code>
<code>cims.model = cims(n.reps=1e3)</code>
  cl = makeCluster(detectCores())
# Highlight and execute the code to fit the Gaussian model to the data.
  cims.model = cims(n.reps=10)
<code>gauss.model = gauss()</code>
  gauss.model = gauss()
</code>
 
'''Model Parameters'''
 
The results for each model are saved to '''cims_out.csv''' and '''gauss_out.csv'''.
 
'''Model Comparison'''
 
Batch comparison within and across conditions
  within_condition_tests(cims.model, gauss.model)
  across_condition_tests(cims.model, gauss.model)
 
Helper files exist to extract the log Likelihood directly for further use
  logLik(cims.model)
  logLik(gauss.model)
 
To plot model fits
<code>
  ebar_plot(asyncs, count_mat/max_count)
  add_fit_line(cims.model)
  add_fit_line(gauss.model)
</code>
 
To obtain the raw predicted values:
<code>
  cims.predicted = predict(cims.model)
  gauss.predicted = predict(gauss.model)
</code>
 
 
To obtain predictions for arbitrary asynchronies for a given subject (here subject 10)
<code>
  params = cims.model$spars[10,]
  new_asyncs = seq(-500, 500, length.out=500)
  predicted = predict.cims.par(new_asyncs, params)
</code>


== Copyright/Licensing ==  
== Copyright/Licensing ==  

Revision as of 10:04, 15 May 2013

Causal Inference of Multisensory Speech Model

NB: This code is in active development

A copy of this help file is included in the code pack as README.txt

If you run into trouble with any step, please contact me: john dot magnotti at gmail dot com. If the model fitting fails to converge for your dataset, you may need to send me at least a portion of the data so I can replicate the error.

If you find this code useful, please cite our work:

Magnotti, J. F., Ma, W. J., & Beauchamp, M. S. (submitted). Causal Inference in Multisensory Speech Perception.

Fitting the CIMS model to your data

System setup

  1. Install GNU R
  2. Download the CIMS CODE PACK (link this to Dropbox)
  3. Extract the zip file to your Desktop/ or other preferred location

Data setup

The model code assumes the data are stored in a matrix format with rows as subjects and each column a separate asynchrony. The first row is used as labels for the columns. Each cell stores the number of times the subject judged the stimulus at the given asynchrony as synchronous. If there are 17 subject and 15 asynchronies, the file will have 18 rows (1st row is header row) and 15 columns. For multi-condition experiments, place each asynchrony/condition combination in a separate column. Asynchronies within a condition must be contiguous. If the study has 4 conditions and 15 asynchronies, then the columns 1-15 will be treated as condition 1, 16-30 as condition 2, and so on. See data.csv in the code pack for the data used in Magnotti, Ma, & Beauchamp.

If you are unfamiliar with R, the best approach is to run through all the model building steps using the included data.csv file, and then try with your own data.

Program setup

We need to ensure R can find the data and code files

  1. Launch R
  2. Open the file fit_models.R: File-> Open Document
  3. We need to make 4 changes before running the code. See the comments in the code file for additional direction
    1. Line 5: Set the path to be the location of the downloaded files. If you extracted the code pack to your desktop, the path may already be correct
    2. Line 11: Set the location of the data to be fit
    3. Line 14: Set the value of max_count to be the total number of trials at each asynchrony for each condition.
    4. Line 17: Set the value of the asynchronies used in each condition. The order of the asynchronies must match the order in the data file. For multiple condition experiments, list the asynchronies only once.
  4. Run the setup code to make sure there are no errors
    1. Highlight lines 1 through 17 using the mouse
    2. Execute the code by using the R menu: Edit -> Execute

Fitting the model

Highlight and execute each of the following lines in turn

  cl = makeCluster(detectCores())
  cims.model = cims(n.reps=10)
  gauss.model = gauss()

Model Parameters

The results for each model are saved to cims_out.csv and gauss_out.csv.

Model Comparison

Batch comparison within and across conditions

  within_condition_tests(cims.model, gauss.model)
  across_condition_tests(cims.model, gauss.model)

Helper files exist to extract the log Likelihood directly for further use

  logLik(cims.model)
  logLik(gauss.model)

To plot model fits

  ebar_plot(asyncs, count_mat/max_count)
  add_fit_line(cims.model)
  add_fit_line(gauss.model)

To obtain the raw predicted values:

  cims.predicted = predict(cims.model)
  gauss.predicted = predict(gauss.model)


To obtain predictions for arbitrary asynchronies for a given subject (here subject 10)

  params = cims.model$spars[10,]
  new_asyncs = seq(-500, 500, length.out=500)
  predicted = predict.cims.par(new_asyncs, params)

Copyright/Licensing

http://i.creativecommons.org/l/by-sa/3.0/88x31.png

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.