SlideShare a Scribd company logo
#-------------------------------------------------------------------------------------
# ERPsimulate
# by D V M Bishop, 18th
June 2013
# Script to accompany blogpost:
# http://deevybee.blogspot.co.uk/2013/06/interpreting-unexpected-significant.html
#-------------------------------------------------------------------------------------
# Create datasets of simulated ERP averages by random number generation
# Assign means to fictitious subjects/conditions/electrodes and use ezANOVA
# to analyse
# ForezANOVA, data are organised in a format where repeated
# measures are stacked below one another
#For each dataset, do ANOVA for 4 way, 3 way (elec as factor) and 2 way (difference score as factor)
require(MASS) #used for multivariate random normal data generation, mvrnorm command
require(ez) #for ezanova
ptm<- proc.time() #500 runs took about 5 mins
nsims=8# n values to simulate for each subject; 2 locs x 2 sides x 2 conditions
mycorrel=0 #intercorrelation between dvs, will be in mysigma matrix
mysigma=matrix(c(rep(mycorrel,nsims*nsims)),nsims,nsims)
for (i in 1:nsims){mysigma[i,i]=1} #ones on diagonal
mymu=rep(0,nsims) #mean is zero
nsub=40 # here 2 groups of 20
mydata=matrix(rep(0,nsub*nsims*8),nsub*nsims,8)#initialise data matrix; 8 cols to include all
possible factors
nrun=20 #N runs through the simulation; ANOVA done for each one; once working, try around 1000
runs
mypvalues=array(0,dim=c(25,nrun)) #initialise array for 4way, 3way and 2way stacked: used to save
ANOVA pvalue outputs - 15 terms altogether
myeffect=0 #this effect will be added to cols 4-8 (one level of 'task' factor); .2 will give a modest
effect
for (myrun in 1:nrun){ # do repeated runs of the simulation
myavg=mvrnorm(n = nsub, mymu, mysigma, empirical = FALSE) #make matrix of random values
#for all subjects with intercorrelation
#determined by mysigma
myavg[,4:8]=myavg[,4:8]+myeffect #constant effect added to cols corresponding to one level of
'task'
for (mysub in 1:nsub){
mygrp=1
if (mysub>20){mygrp=2}#2 groups each of 20 #can change this if desired
startrow=(mysub-1)*(nsims)+1
endrow=mysub*nsims
mydata[startrow:endrow,1]=mysub;#ID in col 1
mydata[startrow:endrow,2]=t(myavg[mysub,]) #simulated avgs stacked in col 2
mydata[startrow:endrow,3]=mygrp;#group in col 3
mydata[startrow:endrow,4]=c(1,1,1,1,2,2,2,2);#task in col 4
mydata[startrow:endrow,5]=c(1,1,2,2,1,1,2,2) #side in col 5
mydata[startrow:endrow,6]=c(1,2,1,2,1,2,1,2) #loc in col 6
mydata[startrow:endrow,7]=c(1,2,3,4,1,2,3,4) #electrode in col 7 (equiv to side x loc)
mydata[startrow:endrow,8]=c(myavg[mysub,1]-myavg[mysub,5],myavg[mysub,2]-
myavg[mysub,6],myavg[mysub,3]-myavg[mysub,7],myavg[mysub,4]-myavg[mysub,8])
#difference between the two levels of task
} #end of mysub loop
mydf=data.frame(mydata)
names(mydf)=c("id","amp","group" ,"task", "side", "loc","elec","diff")
mydf$id<- as.factor(mydf$id)
mydf$group<- as.factor(mydf$group)
mydf$task<- as.factor(mydf$task)
mydf$side<- as.factor(mydf$side)
mydf$loc<- as.factor(mydf$loc)
mydf$elec<- as.factor(mydf$elec)
mydf$diff=as.numeric(mydf$diff)
mydf2 <- mydf[which(mydf$task==1 ), ] #for 2 way Anova, just take rows where task=1 so there's
just one difference value
attach(mydf)
attach(mydf2)
myresult4=ezANOVA(data=mydf, dv=.(amp), wid=.(id), between=.(group),within=.(task, side,loc),
type=3)
myresult3=ezANOVA(data=mydf,dv=.(amp),wid=.(id),between=.(group),within=.(task,elec),type=3)
myresult2=ezANOVA(data=mydf2,dv=.(diff),wid=.(id),between=.(group),within=.(elec),type=3)
detach(mydf)
detach(mydf2)
mypvalues[,myrun]=c(myresult4$ANOVA[,5],myresult3$ANOVA[,5],myresult2$ANOVA[,5]) #5th col
of ANOVA output has pvalues
rownames(mypvalues)=
c(myresult4$ANOVA$Effect,myresult3$ANOVA$Effect,myresult2$ANOVA$Effect)
}
myfilename="mypvalues_all.TXT"
#write.table(mydata, "mydata.txt", sep="t") #write data from last run only to a tab-sep text file; will
be saved in default directory
write.table(t(mypvalues), myfilename, sep="t") #write transposed pvalues to a tab-sep text file; will
be saved in default directory
#First 15 cols will give output for 4-way, next 7 give output for 3-way, and last 3 for 2-way
#NB for 2-way, the 'group' term is equivalent to group x task in other ANOVAs, because dv is task
difference
proc.time()-ptm #check how long it takes to run

More Related Content

What's hot

ゲーム理論BASIC 第2回 -戦略形ゲーム-
ゲーム理論BASIC 第2回 -戦略形ゲーム-ゲーム理論BASIC 第2回 -戦略形ゲーム-
ゲーム理論BASIC 第2回 -戦略形ゲーム-
ssusere0a682
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
Rsquared Academy
 
Furniture
FurnitureFurniture
Furniture
Elif Akkuş
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRead/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
Rsquared Academy
 
Programming Language: Ruby
Programming Language: RubyProgramming Language: Ruby
Programming Language: Ruby
Hesham Shabana
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
Rsquared Academy
 
First step of Performance Tuning
First step of Performance TuningFirst step of Performance Tuning
First step of Performance Tuning
risou
 
Game and Search
Game and SearchGame and Search
Game and Search
Adri Jovin
 
To get user client system name on ui welcome screen.doc
To get user client system name on ui welcome screen.docTo get user client system name on ui welcome screen.doc
To get user client system name on ui welcome screen.doc
Ripunjay Rathaur
 

What's hot (11)

Ruby2.0でlazyな n-Queen
Ruby2.0でlazyな n-QueenRuby2.0でlazyな n-Queen
Ruby2.0でlazyな n-Queen
 
ゲーム理論BASIC 第2回 -戦略形ゲーム-
ゲーム理論BASIC 第2回 -戦略形ゲーム-ゲーム理論BASIC 第2回 -戦略形ゲーム-
ゲーム理論BASIC 第2回 -戦略形ゲーム-
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
 
Furniture
FurnitureFurniture
Furniture
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRead/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
 
Programming Language: Ruby
Programming Language: RubyProgramming Language: Ruby
Programming Language: Ruby
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
 
First step of Performance Tuning
First step of Performance TuningFirst step of Performance Tuning
First step of Performance Tuning
 
Game and Search
Game and SearchGame and Search
Game and Search
 
To get user client system name on ui welcome screen.doc
To get user client system name on ui welcome screen.docTo get user client system name on ui welcome screen.doc
To get user client system name on ui welcome screen.doc
 
Sol3
Sol3Sol3
Sol3
 

Similar to ERPsimulate_script

Maze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docx
Maze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docxMaze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docx
Maze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docx
andreecapon
 
Computer Science Homework Help
Computer Science Homework HelpComputer Science Homework Help
Computer Science Homework Help
Programming Homework Help
 
Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)
Ben Pope
 
Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbksh
Ben Pope
 
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
computersmartdwarka
 
sports-teampackage.bluej#BlueJ package fileobjectbench.heig.docx
sports-teampackage.bluej#BlueJ package fileobjectbench.heig.docxsports-teampackage.bluej#BlueJ package fileobjectbench.heig.docx
sports-teampackage.bluej#BlueJ package fileobjectbench.heig.docx
whitneyleman54422
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Predictions European Championships 2020
Predictions European Championships 2020Predictions European Championships 2020
Predictions European Championships 2020
Ruben Kerkhofs
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
Paweł Dawczak
 
ChatGPT in Education
ChatGPT in EducationChatGPT in Education
ChatGPT in Education
Victor del Rosal
 
Beautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsBeautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsJesse Donat
 
you need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfyou need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdf
adnankhan605720
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latest
Atifkhilji
 
M12 random forest-part01
M12 random forest-part01M12 random forest-part01
M12 random forest-part01
Raman Kannan
 
Plsql examples
Plsql examplesPlsql examples
Plsql examples
srinivas sunkara
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
aquacareser
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
aquapariwar
 
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
Penetration Testing for Easy RM to MP3 Converter Application and Post ExploitPenetration Testing for Easy RM to MP3 Converter Application and Post Exploit
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
JongWon Kim
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
annikasarees
 
25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator
PravinDhanrao3
 

Similar to ERPsimulate_script (20)

Maze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docx
Maze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docxMaze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docx
Maze Solver - Rubric.xlsxSheet1Maze Solver - RubricStudent Nam.docx
 
Computer Science Homework Help
Computer Science Homework HelpComputer Science Homework Help
Computer Science Homework Help
 
Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)
 
Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbksh
 
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
#Covnet model had been defined class ConvNetNew(torch.nn.Module).pdf
 
sports-teampackage.bluej#BlueJ package fileobjectbench.heig.docx
sports-teampackage.bluej#BlueJ package fileobjectbench.heig.docxsports-teampackage.bluej#BlueJ package fileobjectbench.heig.docx
sports-teampackage.bluej#BlueJ package fileobjectbench.heig.docx
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Predictions European Championships 2020
Predictions European Championships 2020Predictions European Championships 2020
Predictions European Championships 2020
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
ChatGPT in Education
ChatGPT in EducationChatGPT in Education
ChatGPT in Education
 
Beautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsBeautiful PHP CLI Scripts
Beautiful PHP CLI Scripts
 
you need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfyou need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdf
 
DeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latestDeVry GSP 115 Week 3 Assignment latest
DeVry GSP 115 Week 3 Assignment latest
 
M12 random forest-part01
M12 random forest-part01M12 random forest-part01
M12 random forest-part01
 
Plsql examples
Plsql examplesPlsql examples
Plsql examples
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
Penetration Testing for Easy RM to MP3 Converter Application and Post ExploitPenetration Testing for Easy RM to MP3 Converter Application and Post Exploit
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
 
25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator25 MARCH1 list, generator.pdf list generator
25 MARCH1 list, generator.pdf list generator
 

More from Dorothy Bishop

Exercise/fish oil intervention for dyslexia
Exercise/fish oil intervention for dyslexiaExercise/fish oil intervention for dyslexia
Exercise/fish oil intervention for dyslexia
Dorothy Bishop
 
Open Research Practices in the Age of a Papermill Pandemic
Open Research Practices in the Age of a Papermill PandemicOpen Research Practices in the Age of a Papermill Pandemic
Open Research Practices in the Age of a Papermill Pandemic
Dorothy Bishop
 
Language-impaired preschoolers: A follow-up into adolescence.
Language-impaired preschoolers: A follow-up into adolescence.Language-impaired preschoolers: A follow-up into adolescence.
Language-impaired preschoolers: A follow-up into adolescence.
Dorothy Bishop
 
Journal club summary: Open Science save lives
Journal club summary: Open Science save livesJournal club summary: Open Science save lives
Journal club summary: Open Science save lives
Dorothy Bishop
 
Short talk on 2 cognitive biases and reproducibility
Short talk on 2 cognitive biases and reproducibilityShort talk on 2 cognitive biases and reproducibility
Short talk on 2 cognitive biases and reproducibility
Dorothy Bishop
 
Otitis media with effusion: an illustration of ascertainment bias
Otitis media with effusion: an illustration of ascertainment biasOtitis media with effusion: an illustration of ascertainment bias
Otitis media with effusion: an illustration of ascertainment bias
Dorothy Bishop
 
Insights from psychology on lack of reproducibility
Insights from psychology on lack of reproducibilityInsights from psychology on lack of reproducibility
Insights from psychology on lack of reproducibility
Dorothy Bishop
 
What are metrics good for? Reflections on REF and TEF
What are metrics good for? Reflections on REF and TEFWhat are metrics good for? Reflections on REF and TEF
What are metrics good for? Reflections on REF and TEF
Dorothy Bishop
 
Biomarkers for psychological phenotypes?
Biomarkers for psychological phenotypes?Biomarkers for psychological phenotypes?
Biomarkers for psychological phenotypes?
Dorothy Bishop
 
Data simulation basics
Data simulation basicsData simulation basics
Data simulation basics
Dorothy Bishop
 
Simulating data to gain insights into power and p-hacking
Simulating data to gain insights intopower and p-hackingSimulating data to gain insights intopower and p-hacking
Simulating data to gain insights into power and p-hacking
Dorothy Bishop
 
Talk on reproducibility in EEG research
Talk on reproducibility in EEG researchTalk on reproducibility in EEG research
Talk on reproducibility in EEG research
Dorothy Bishop
 
What is Developmental Language Disorder
What is Developmental Language DisorderWhat is Developmental Language Disorder
What is Developmental Language Disorder
Dorothy Bishop
 
Developmental language disorder and auditory processing disorder: 
Same or di...
Developmental language disorder and auditory processing disorder: 
Same or di...Developmental language disorder and auditory processing disorder: 
Same or di...
Developmental language disorder and auditory processing disorder: 
Same or di...
Dorothy Bishop
 
Fallibility in science: Responsible ways to handle mistakes
Fallibility in science: Responsible ways to handle mistakesFallibility in science: Responsible ways to handle mistakes
Fallibility in science: Responsible ways to handle mistakes
Dorothy Bishop
 
Improve your study with pre-registration
Improve your study with pre-registrationImprove your study with pre-registration
Improve your study with pre-registration
Dorothy Bishop
 
Introduction to simulating data to improve your research
Introduction to simulating data to improve your researchIntroduction to simulating data to improve your research
Introduction to simulating data to improve your research
Dorothy Bishop
 
Southampton: lecture on TEF
Southampton: lecture on TEFSouthampton: lecture on TEF
Southampton: lecture on TEF
Dorothy Bishop
 
Reading list: What’s wrong with our universities
Reading list: What’s wrong with our universitiesReading list: What’s wrong with our universities
Reading list: What’s wrong with our universities
Dorothy Bishop
 
IJLCD Winter Lecture 2016-7 : References
IJLCD Winter Lecture 2016-7 : ReferencesIJLCD Winter Lecture 2016-7 : References
IJLCD Winter Lecture 2016-7 : References
Dorothy Bishop
 

More from Dorothy Bishop (20)

Exercise/fish oil intervention for dyslexia
Exercise/fish oil intervention for dyslexiaExercise/fish oil intervention for dyslexia
Exercise/fish oil intervention for dyslexia
 
Open Research Practices in the Age of a Papermill Pandemic
Open Research Practices in the Age of a Papermill PandemicOpen Research Practices in the Age of a Papermill Pandemic
Open Research Practices in the Age of a Papermill Pandemic
 
Language-impaired preschoolers: A follow-up into adolescence.
Language-impaired preschoolers: A follow-up into adolescence.Language-impaired preschoolers: A follow-up into adolescence.
Language-impaired preschoolers: A follow-up into adolescence.
 
Journal club summary: Open Science save lives
Journal club summary: Open Science save livesJournal club summary: Open Science save lives
Journal club summary: Open Science save lives
 
Short talk on 2 cognitive biases and reproducibility
Short talk on 2 cognitive biases and reproducibilityShort talk on 2 cognitive biases and reproducibility
Short talk on 2 cognitive biases and reproducibility
 
Otitis media with effusion: an illustration of ascertainment bias
Otitis media with effusion: an illustration of ascertainment biasOtitis media with effusion: an illustration of ascertainment bias
Otitis media with effusion: an illustration of ascertainment bias
 
Insights from psychology on lack of reproducibility
Insights from psychology on lack of reproducibilityInsights from psychology on lack of reproducibility
Insights from psychology on lack of reproducibility
 
What are metrics good for? Reflections on REF and TEF
What are metrics good for? Reflections on REF and TEFWhat are metrics good for? Reflections on REF and TEF
What are metrics good for? Reflections on REF and TEF
 
Biomarkers for psychological phenotypes?
Biomarkers for psychological phenotypes?Biomarkers for psychological phenotypes?
Biomarkers for psychological phenotypes?
 
Data simulation basics
Data simulation basicsData simulation basics
Data simulation basics
 
Simulating data to gain insights into power and p-hacking
Simulating data to gain insights intopower and p-hackingSimulating data to gain insights intopower and p-hacking
Simulating data to gain insights into power and p-hacking
 
Talk on reproducibility in EEG research
Talk on reproducibility in EEG researchTalk on reproducibility in EEG research
Talk on reproducibility in EEG research
 
What is Developmental Language Disorder
What is Developmental Language DisorderWhat is Developmental Language Disorder
What is Developmental Language Disorder
 
Developmental language disorder and auditory processing disorder: 
Same or di...
Developmental language disorder and auditory processing disorder: 
Same or di...Developmental language disorder and auditory processing disorder: 
Same or di...
Developmental language disorder and auditory processing disorder: 
Same or di...
 
Fallibility in science: Responsible ways to handle mistakes
Fallibility in science: Responsible ways to handle mistakesFallibility in science: Responsible ways to handle mistakes
Fallibility in science: Responsible ways to handle mistakes
 
Improve your study with pre-registration
Improve your study with pre-registrationImprove your study with pre-registration
Improve your study with pre-registration
 
Introduction to simulating data to improve your research
Introduction to simulating data to improve your researchIntroduction to simulating data to improve your research
Introduction to simulating data to improve your research
 
Southampton: lecture on TEF
Southampton: lecture on TEFSouthampton: lecture on TEF
Southampton: lecture on TEF
 
Reading list: What’s wrong with our universities
Reading list: What’s wrong with our universitiesReading list: What’s wrong with our universities
Reading list: What’s wrong with our universities
 
IJLCD Winter Lecture 2016-7 : References
IJLCD Winter Lecture 2016-7 : ReferencesIJLCD Winter Lecture 2016-7 : References
IJLCD Winter Lecture 2016-7 : References
 

Recently uploaded

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

ERPsimulate_script

  • 1. #------------------------------------------------------------------------------------- # ERPsimulate # by D V M Bishop, 18th June 2013 # Script to accompany blogpost: # http://deevybee.blogspot.co.uk/2013/06/interpreting-unexpected-significant.html #------------------------------------------------------------------------------------- # Create datasets of simulated ERP averages by random number generation # Assign means to fictitious subjects/conditions/electrodes and use ezANOVA # to analyse # ForezANOVA, data are organised in a format where repeated # measures are stacked below one another #For each dataset, do ANOVA for 4 way, 3 way (elec as factor) and 2 way (difference score as factor) require(MASS) #used for multivariate random normal data generation, mvrnorm command require(ez) #for ezanova ptm<- proc.time() #500 runs took about 5 mins nsims=8# n values to simulate for each subject; 2 locs x 2 sides x 2 conditions mycorrel=0 #intercorrelation between dvs, will be in mysigma matrix mysigma=matrix(c(rep(mycorrel,nsims*nsims)),nsims,nsims) for (i in 1:nsims){mysigma[i,i]=1} #ones on diagonal mymu=rep(0,nsims) #mean is zero nsub=40 # here 2 groups of 20 mydata=matrix(rep(0,nsub*nsims*8),nsub*nsims,8)#initialise data matrix; 8 cols to include all possible factors nrun=20 #N runs through the simulation; ANOVA done for each one; once working, try around 1000 runs mypvalues=array(0,dim=c(25,nrun)) #initialise array for 4way, 3way and 2way stacked: used to save ANOVA pvalue outputs - 15 terms altogether myeffect=0 #this effect will be added to cols 4-8 (one level of 'task' factor); .2 will give a modest effect for (myrun in 1:nrun){ # do repeated runs of the simulation myavg=mvrnorm(n = nsub, mymu, mysigma, empirical = FALSE) #make matrix of random values #for all subjects with intercorrelation #determined by mysigma myavg[,4:8]=myavg[,4:8]+myeffect #constant effect added to cols corresponding to one level of 'task' for (mysub in 1:nsub){ mygrp=1
  • 2. if (mysub>20){mygrp=2}#2 groups each of 20 #can change this if desired startrow=(mysub-1)*(nsims)+1 endrow=mysub*nsims mydata[startrow:endrow,1]=mysub;#ID in col 1 mydata[startrow:endrow,2]=t(myavg[mysub,]) #simulated avgs stacked in col 2 mydata[startrow:endrow,3]=mygrp;#group in col 3 mydata[startrow:endrow,4]=c(1,1,1,1,2,2,2,2);#task in col 4 mydata[startrow:endrow,5]=c(1,1,2,2,1,1,2,2) #side in col 5 mydata[startrow:endrow,6]=c(1,2,1,2,1,2,1,2) #loc in col 6 mydata[startrow:endrow,7]=c(1,2,3,4,1,2,3,4) #electrode in col 7 (equiv to side x loc) mydata[startrow:endrow,8]=c(myavg[mysub,1]-myavg[mysub,5],myavg[mysub,2]- myavg[mysub,6],myavg[mysub,3]-myavg[mysub,7],myavg[mysub,4]-myavg[mysub,8]) #difference between the two levels of task } #end of mysub loop mydf=data.frame(mydata) names(mydf)=c("id","amp","group" ,"task", "side", "loc","elec","diff") mydf$id<- as.factor(mydf$id) mydf$group<- as.factor(mydf$group) mydf$task<- as.factor(mydf$task) mydf$side<- as.factor(mydf$side) mydf$loc<- as.factor(mydf$loc) mydf$elec<- as.factor(mydf$elec) mydf$diff=as.numeric(mydf$diff) mydf2 <- mydf[which(mydf$task==1 ), ] #for 2 way Anova, just take rows where task=1 so there's just one difference value attach(mydf) attach(mydf2) myresult4=ezANOVA(data=mydf, dv=.(amp), wid=.(id), between=.(group),within=.(task, side,loc), type=3) myresult3=ezANOVA(data=mydf,dv=.(amp),wid=.(id),between=.(group),within=.(task,elec),type=3) myresult2=ezANOVA(data=mydf2,dv=.(diff),wid=.(id),between=.(group),within=.(elec),type=3) detach(mydf) detach(mydf2) mypvalues[,myrun]=c(myresult4$ANOVA[,5],myresult3$ANOVA[,5],myresult2$ANOVA[,5]) #5th col of ANOVA output has pvalues rownames(mypvalues)= c(myresult4$ANOVA$Effect,myresult3$ANOVA$Effect,myresult2$ANOVA$Effect) } myfilename="mypvalues_all.TXT" #write.table(mydata, "mydata.txt", sep="t") #write data from last run only to a tab-sep text file; will be saved in default directory
  • 3. write.table(t(mypvalues), myfilename, sep="t") #write transposed pvalues to a tab-sep text file; will be saved in default directory #First 15 cols will give output for 4-way, next 7 give output for 3-way, and last 3 for 2-way #NB for 2-way, the 'group' term is equivalent to group x task in other ANOVAs, because dv is task difference proc.time()-ptm #check how long it takes to run