plot(confidence)
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
didLook
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
runModel(par)
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
runModel(par)
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
runModel(par)
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
out$bet
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
w
rateSamples
?ifelse
bet
runif(1) < par$trueRate
rateSamples
w
sample(rateSamples, par$nParticles, TRUE, w)
ifelse( runif(1) < par$trueRate, rateSamples, 1-rateSamples )
ifelse( (runif(1) < par$trueRate), rateSamples, 1-rateSamples )
rateSamples[1]
rateSamples[2]
?switch
switch(runif(1) < par$trueRate, TRUE=1, FALSE=0 )
switch(runif(1) < par$trueRate, "TRUE"=1, "FALSE"=0 )
switch(runif(1) < par$trueRate, "TRUE"=rateSamples, "FALSE"=1-rateSamples )
?ifelse
Q
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
w
length(w)
length(rateSamples)
par$nParticles
browser()
rateSamples <- sample(rateSamples, par$nParticles, TRUE, w) # resample
rateSamples
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
Q
?browserSetDebug
debugonce(runModel)
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
runModel(par)
isdebugged(runModel)
debugonce(runModel)
isdebugged(runModel)
runModel(par)
runModel(par)
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
out
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
out
out$bet
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
out$mean
out$bet
rowMeans( out$bet )
colMeans( out$bet )
plot( colMeans( out$bet ))
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
plot( colMeans( out$bet ))
plot( colMeans( out$evidence ))
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
bet
out$bet
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
source('~/Work/Research/DecisionMaking/InformationReward/quickModel.R')
library(lsr)
chapek9.xtabs <- xtabs( ~ choice + species, data = chapek9)
chapek9.xtabs
cramersV( chapek9.xtabs )
cramersV
load( "chico.Rdata")
wideToLong(chico  )
View(dwr.wide)
View(dwr.wide)
library(lsr)
wideToLong( dwr.wide )
wideToLong( dwr.wide, within=c("drug","time") )
?longTowide
?longToWide
longToWide( dwr.long, wm + rt ~ drug + time )
load("/Users/dan/Work/Research/Rbook/csiro_workshop/toydata.Rdata")
expt$treatment
permuteLevels(
expt$treatment,
c(2,3,1)
)
permuteLevels(
expt$treatment,
c(2,3,1)
)
ages <- c(16,16,16,17,17,17,18,18,18,18,18,19,19,19,22,24,25,28,30,31,37,41,45,48,55,57,60)
hist(ages)
cut(ages,3)
quantileCut(ages,3)
ages <- c(16,16,16,17,17,17,18,18,18,18,18,19,19,19,22,24,25,28,30,31,37,41,45,48,55,57,60)
hi
hist(ages, col="blue")
hist(ages, col="light blue")
hist(ages, col="light blue", breaks=18:60)
hist(ages, col="light blue", breaks=17:61)
min(ages)
max(ages)
hist(ages, col="light blue", breaks=17:65)
hist(ages, col="light blue", breaks=15:65)
hist(ages, col="light blue", breaks=15:60)
hist(ages, col="light blue", breaks=16:60)
dev.print(pdf,file="~/Work/Research/Rbook/csiro_workshop/my_img/hist5.pdf",width=6,height=6)
cut(ages,3)
table( cut(ages,3))
ages
quantileCut(ages,3)
table( quantileCut(ages,3) )
?cut
cut( ages, 3 )
cut( ages, 3 )
library(lsr)
quantileut( ages, 3 )
library(lsr)
quantileCut( ages, 3 )
cut( ages, breaks=c(16,22,35,60))
cut( ages, breaks=c(15,22,35,60))
ageGroups <- cut(ages,3)
levels( ageGroups ) <- c("young","middle","old")
ageGropus
ageGroups
ageGroups <- cut(ages,3)
levels( ageGroups ) <- c("young","middle","old")
ageGroups
eyeColour <- c( "blue", "blue", "green", "brown", "green" )
class( eyeColour )
eyeColour <- as.factor( eyeColour )
eyeColour
class( eyeColour )
age <- c("17", "19", "30", "37", "thirty")
class(age )
age <- as.numeric( age )
age
class(age)
isYoung <- age < 30
isYoung
class( isYoung )
is
isYoung <- as.numeric( isYoung )
isYoung
class( isYoung )
date <- c("11-sep-2013","11-09-2013")
as.Date( date )
?date
date <- c("11-sep-2013","11-jan-2013")
as.Date(date)
date <- c("11-Sep-2013","11-Jan-2013")
as.Date(date)
?as.Date
date <- c("11-09-2013","11-01-2013")
as.Date( date )
date <- c("2013-09-13","2013-01-20")
as.Date(date)
Sig <- matrix( runif(100)*.2-.1, 10, 10 )
Sig
source('~/Work/Research/Rbook/csiro_workshop/my_img/fake2Factor.R')
Sig
heatmap( Sig )
source('~/Work/Research/Rbook/csiro_workshop/my_img/fake2Factor.R')
heatmap( Sig )
Sig
source('~/Work/Research/Rbook/csiro_workshop/my_img/fake2Factor.R')
Sig
library(MASS)
?mvnorm
?mvrnorm
questionnaire <- mvnorm( n=100, mu=4, Sigma=Sig )
questionnaire <- mvrnorm( n=100, mu=4, Sigma=Sig )
questionnaire <- mvrnorm( n=100, mu=rep.int(4,10), Sigma=Sig )
questionnaire
questionnaire <- mvrnorm( n=100, mu=rep.int(4,10), Sigma=Sig*2 )
questionnaire
round(questionnaire)
source('~/Work/Research/Rbook/csiro_workshop/my_img/fake2Factor.R')
rownames(questionnaire) <- c( paste0("A",1:5), paste0("B",1:5))
library(MASS)
questionnaire <- mvrnorm( n=100, mu=rep.int(4,10), Sigma=Sig*2 )
questionnaire <- round(questionnaire)
questionnaire[ questionnaire < 1 ] <- 1
questionnaire[ questionnaire > 7 ] <- 7
colnames(questionnaire) <- c( paste0("A",1:5), paste0("B",1:5))
questionnaire
correlate( questionnaire )
correlate( questionnaire, test=TREU )
correlate( questionnaire, test=TRUE )
library(psych)
alpha( questionnaire )
factanal( questionnaire, 2 )
save( questionnaire, "../../csiro_workshop/surveysays.Rdata")
save( questionnaire, file="../../csiro_workshop/surveysays.Rdata")
questionnaire
questionnaire <- as.data.frame( questionnaire )
questionnaire
factanal( questionnaire, 2 )
save( questionnaire, file="../../csiro_workshop/surveysays.Rdata")
questionnaire
correlate( questionnaire )
correlate( questionnaire, test=TRUE )
factanal( questionnaire, factors=2 )
factanal( questionnaire, factors=3 )
factanal( questionnaire, factors=2 )
?factanal
library(psych)
?psych
install.packages("nFactors")
library(nFactors)
?parallel
install.packages("GPArotation")
library(GPArotation)
?GPArotation
help("package:GPArotatio")
help("package:GPArotation")
?factanal
?psych
alpha( questionnaire[,1:5] )
alpha( questionnaire[,6:10] )
?alpha
library(bayesFactor)
library(BayesFactor)
?BayesFactor
?ttestBF
ttestBF( formula = happy ~ gender, data = expt )
t.test( happy ~ gender, expt )
expt
?BayesFactor
anovaBF( happy ~ treatment, expt )
anova( lm( happy ~ treatment, expt ))
anova( lm( hormone ~ treatment, expt ))
load("/Users/dan/Work/Research/Rbook/csiro_workshop/clinicaltrial.Rdata")
clin.trial
bars( mood.gain ~ drug + therapy, clin.trial )
dev.print(pdf,file="../my_img/errorbar10.pdf",width=6,height=6)
dev.print(pdf,file="~/Work/Research/Rbook/csiro_workshop/my_img/errorbar10.pdf",width=6,height=6)
library(car)
library(car)
Anova( aov(  mood.gain ~ drug * therapy, clin.trial  ))
anovaBF( mood.gain ~ drug * therapy, clin.trial )
?anovaBF
anovaBF( mood.gain ~ drug * therapy, clin.trial, whichModels="all" )
anovaBF( happy ~ treatment, expt )
anovaBF( happy ~ treatment + gender , expt )
bars( happy ~ treatment + gender, expt )
dev.print(pdf,file="../my_img/errorbar11.pdf",width=6,height=6)
dev.print(pdf,file="~/Work/Research/Rbook/csiro_workshop/my_img/errorbar11.pdf",width=6,height=6)
anovaBF( happy ~ treatment + gender , expt )
Anova( aov( happy ~ treatment + gender , expt ))
Anova( aov( happy ~ treatment * gender , expt ))
age <- 34
age
age + 10
age
# define variable initially
age <- 34
age
# get R to print age+10
age + 10
# the age variable is still 34
age
# but we can overwrite:
age <- age + 10
age
quadruple <- function( x ) { y <- x*4; return(y) }
quadruple( 9 )
quadruple( x=c(2,3,4) )
today <- "Thursday"
if( today == "Thursday" ) { happy <- TRUE } else { happy <- FALSE }
happy
amHappy <- function( day ) { }
amHappy <- function( day ) {
if( day=="Thursday" ) { happy <-TRUE } else { happy <- FALSE }
return( happy )
}
amHappy( "green" )
amHappy( "Thursday" )
amHappy( "THURSDAY" )
firstFivePowers <- function( x ) {}
firstFivePowers <- function( x ) {
y <- vector()
for( i in 1:5 ) {
y[i] <- x^i
}
return(y)
}
firstFivePowers( 3 )
firstFivePowers( 10 )
firstFivePowers( 2 )
firstFivePowers( 2 )
firstFivePowers( 3 )
age
age <- 1
age <- 34
name <- "Dan"
rm( age )
expy
expt
load("/Users/dan/Work/Research/Rbook/csiro_workshop/toydata.Rdata")
exot
expt
expt$hormone
expt$id
toydata[1,]
expt[1,]
expt[ 1:3, ]
expt[ 4, ]
expt[ c(1,4,7), ]
expt[ c(1,4,7), c("age","gender") ]
theMales <- expt$gender == "male"
expt[ theMales, ]
expt[ theMales, ]
expt[1, "age"]
expt[1,2]
expt$age + 100
expt$age[1] <- 1000
expt
expt$age[1] <- 25
expt
expt$over30 <- expt$age > 30
expt
expt$over25 <- expt$age > 25
expt
expt <- expt[ , -over30]
exot
rm( over30, envir=expt)
expt <- expt[, -8 ]
expt
expt$over25 <- expt$age > 25
expt
expt <- expt[,names(expt) != "over25"]
expt
?subset
droplevels(expt,"sad")
class( expt$gender )
myList <- list( age=34, name="Dan", isNerd=TRUE )
myList
matrix( data=1:20, nrow=4, ncol=5 )
boredom <- c( time1 = 0.52, time2 = 0.82, time3 = 0.99 )
boredom
osx <- c( 10.6 = Hera (1.0) Kodiak (Public Beta) Cheetah (10.0) Puma (10.1) Jaguar (10.2) Panther (10.3) Tiger (10.4) Leopard (10.5) Snow Leopard (10.6) Lion (10.7) Mountain Lion (10.8) Mavericks (10.9))
osx <- c( 10.7 = "Lion", 10.8 = "Mountain Lion", 10.9 = "Mavericks" )
osx <- c( "10.7" = "Lion", "10.8" = "Mountain Lion", "10.9" = "Mavericks" )
osx
osx <- c( 107 = "Lion", 108 = "Mountain Lion", 109 = "Mavericks" )
osx <- c( "10.7" = "Lion", "10.8" = "Mountain Lion", "10.9" = "Mavericks" )
osx
osx[1]
age <- c( 23, 11, 91, 5 )
age[3]
age[ c(1,3) ]
age[ -1 ]
bordeom[ time1 ]
boredom[ time1 ]
boredom[ "time1" ]
boredom[ c("time3", "time1") ]
boredom[ c(TRUE, FALSE, FALSE) ]
boredom[ c(TRUE, FALSE, TRUE) ]
boredom[ boredom > .7 ]
boredom > .7
boredome[ boredom > .7 ]
boredom[ boredom > .7 ]
boredom > .7
boredom[ boredom > .7 ]
expt$gender
expt$happy
expt$happy
library(lsr)
oneSampleTTest( x=grades, mu=67.5 )
?oneSampleTTest
install.packages("RWiener")
library(RWiener)
?rwiener
load("/Users/dan/Work/Research/Rbook/book/data/harpo.Rdata")
harpo
independentSamplesTTest( formula = grade ~ tutor,
data = harpo,
var.equal = TRUE )
load("/Users/dan/Work/Research/Rbook/book/data/harpo.Rdata")
library(devtools)
install_bitbucket("lsr-package","dannavarro")
library(lsr)
?lsr
independentSamplesTTest( formula = grade ~ tutor, data = harpo, var.equal = TRUE)
independentSamplesTTest( formula = grade ~ tutor, data = harpo, var.equal = TRUE)
independentSamplesTTest( formula = grade ~ tutor, data = harpo )
?pairedSamplesTTest
load("/Users/dan/Work/Research/Rbook/book/data/chico.Rdata")
chico
chico2 <- wideToLong( chico )
chico2
load("/Users/dan/Work/Research/Rbook/book/data/chico.Rdata")
chico2 <- wideToLong( chico, within="time" )
head(chico2)
chico2
bars( grade ~ time, chico2 )
chico$improvement <- chico$grade_test2 - chico$grade_test1
oneSampleTTest( chico$improvement, mu=0 )
oneSampleTTest( chico$grade_test2 - chico$grade_test1, mu=0 )
pairedSamplesTTest(
formula = grade ~ time,
data = chico2,
id = id
)
?pairedSamplesTTest
?pairedSamplesTTest
?pairedSamplesTTest
pairedSamplesTTest
pairedSamplesTTest(
formula = grade ~ time,
data = chico2,
id = "id"
)
t.test( x=grades, mu=67.5 )
load("/Users/dan/Work/Research/Rbook/book/data/zeppo.Rdata")
t.test( x=grades, mu=67.5 )
t.test( x=chico$grade_test1, y=chico$grade_test2, paired=TRUE )
t.test( x=chico$grade_test2, y=chico$grade_test1, paired=TRUE )
clin.trial
