Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lei-zhang committed Apr 1, 2019
1 parent bad64a6 commit 9879bd9
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 131 deletions.
254 changes: 127 additions & 127 deletions 01.R_basics/.Rhistory
Original file line number Diff line number Diff line change
@@ -1,130 +1,3 @@
sprintf('sub%02i/raw_data_sub%04.2f.txt',10,9)
sprintf('sub%02i/raw_data_sub%05.2f.txt',10,9)
sprintf('sub%02i/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%02i/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%02d/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%03d/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%03i/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%3i/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%03i/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%03i/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%03d/raw_data_sub%06.2f.txt',10,9)
sprintf('sub%03d/raw_data_sub%07.2f.txt',10,9)
sprintf('sub%03d/raw_data_sub%03.2f.txt',10,9)
sprintf('sub%03d/raw_data_sub%03.3f.txt',10,9)
ns = 10
data_dir = '_data/RL_raw_data'
rawdata = c();
for (s in 1:ns) {
sub_file = file.path(data_dir, sprintf('sub%02i/raw_data_sub%02i.txt',s,s))
sub_data = read.table(sub_file, header = T, sep = ",")
rawdata = rbind(rawdata, sub_data)
}
dim(rawdata)
rawdata = rawdata[complete.cases(rawdata),]
dim(rawdata)
rawdata$choice == rawdata$correct
(rawdata$choice == rawdata$correct) * 1.0
rawdata$accuracy = (rawdata$choice == rawdata$correct) * 1.0
head(rawdara)
head(rawdata)
aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)
acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
aggregate(rawdata$accuracy, by = list(rawdata$trialID), mean)
#------------------------------------------------------------------------------
# read descriptive data
load('_data/RL_descriptive.RData')
descriptive
#------------------------------------------------------------------------------
# read descriptive data
load('_data/RL_descriptive.RData')
descriptive$acc = acc_mean
df = descriptive
df
#------------------------------------------------------------------------------
# read descriptive data
load('_data/RL_descriptive.RData')
descriptive
descriptive$acc = acc_mean
descriptive$acc = acc_mean
df = descriptive
#------------------------------------------------------------------------------
# one sample t-test , to test if 'acc' is above chance level
t.test(df$acc, mu = 0.5)
# simple correlation, to test if IQ is correlated with acc
cor.test(df$IQ, df$acc)
df
g1 <- ggplot(df, aes(IQ,acc))
library
#------------------------------------------------------------------------------
## plot the scatter and the regression line
library(ggplot2)
myconfig <- theme_bw(base_size = 20) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank() )
# scatter plot
g1 <- ggplot(df, aes(IQ,acc))
g1
library(ggplot2)
myconfig <- theme_bw(base_size = 20) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank() )
g1 <- ggplot(df, aes(IQ,acc))
g1
g1 <- g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.95)
g1
g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.1)
g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.1)
g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0)
g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.9)
g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='red', alpha=0.9)
g1 + geom_jitter(width=0.0, height=0.0, size=1, colour='red', alpha=0.9)
g1 + geom_jitter(width=0.0, height=0.0, size=1, colour='red', fill = 'green', alpha=0.9)
g1 + geom_jitter(width=1, height=1, size=1, colour='red', fill = 'green', alpha=0.9)
g1 + geom_jitter(width=1, height=1, size=1, colour='red', fill = 'green', alpha=0.9)
g1 + geom_jitter(width=1, height=1, size=1, colour='red', fill = 'green', alpha=0.9)
g1 + geom_jitter(width=1, height=1, size=1, colour='red', fill = 'green', alpha=0.9)
g1 + geom_jitter(width=1, height=1, size=1, colour='red', fill = 'green', alpha=0.9)
g1 + geom_jitter(width=1, height=1, size=1, colour='red', fill = 'green', alpha=0.9)
g1 <- g1 + myconfig + labs(x = 'IQ', y = 'Choice accuracy (%)')
g1
g1 <- g1 + geom_smooth(method = "lm", se = T, colour='skyblue3')
g1
g1 <- ggplot(df, aes(Age,acc))
g1 <- g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.95)
g1 <- g1 + myconfig + labs(x = 'Age', y = 'Choice accuracy (%)')
# add the regression line
g1 <- g1 + geom_smooth(method = "lm", se = T, colour='skyblue3')
g1
cor.test(df$Age, df$acc)
cor.test(df$IQ, df$acc)
0.8631401 ^2
# scatter plot
g1 <- ggplot(df, aes(IQ,acc))
?gemo_jitter
?geom_jitter
g1 + geom_jitter(width=0.0, height=0.0, size=2, colour='skyblue', alpha=0.95)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='skyblue', alpha=0.95)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='red', alpha=0.95)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='red', alpha=0.5)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='red', alpha=0.1)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='red', fill='green', alpha=0.1)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='red', alpha=0.1)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='red', alpha=0.9)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='skybule3', alpha=0.9)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='skyblue3', alpha=0.9)
g1 + geom_jitter(width=0.0, height=0.0, size=3, colour='skyblue3', alpha=0.3)
g1 + geom_jitter(width=0.0, height=0.0, size=10, colour='skyblue3', alpha=0.3)
g1 + geom_jitter(width=0.0, height=0.0, size=10, colour='red', alpha=0.3)
g1 + geom_jitter(width=0.0, height=0.0, size=10, colour='red', alpha=0.1)
g1 + geom_jitter(width=0.0, height=0.0, size=10, colour='red', alpha=0.95)
## simple regression
fit1 = lm(acc ~ IQ, data = df)
fit2 = lm(acc ~ Age, data = df)
fit3 = lm(acc ~ IQ + Age, data = df)
fit4 = lm(acc ~ IQ * Age, data = df)
summary(fit1)
summary(fit2)
summary(fit3)
Expand Down Expand Up @@ -510,3 +383,130 @@ acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
install.packages('brms')
install.packages('tidyverse')
library(brms)
data_dir = ('_data/RL_raw_data/sub01/raw_data_sub01.txt')
data = read.table(data_dir, header = T, sep = ",")
head(data)
# rm NAs
sum(complete.cases(data))
data = data[complete.cases(data),]
dim(data[complete.cases(data),])
# indexing
data[1,1]
data[1,]
data[,1]
data[1:10,]
data[,1:2]
data[1:10, 1:2]
data[c(1,3,5,6), c(2,4)]
data$choice
# read in all the data!
ns = 10
data_dir = '_data/RL_raw_data'
rawdata = c();
for (s in 1:ns) {
sub_file = file.path(data_dir, sprintf('sub%02i/raw_data_sub%02i.txt',s,s))
sub_data = read.table(sub_file, header = T, sep = ",")
rawdata = rbind(rawdata, sub_data)
}
rawdata = rawdata[complete.cases(rawdata),]
rawdata$accuracy = (rawdata$choice == rawdata$correct) * 1.0
acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
acc_mean
as.matrix(acc_mean, 10, 1)
0.8631^2
?cor.test
load('_data/RL_descriptive.RData')
descriptive$acc = acc_mean
df = descriptive
df
ns = 10
data_dir = '_data/RL_raw_data'
rawdata = c();
for (s in 1:ns) {
sub_file = file.path(, sprintf('sub%02i/raw_data_sub%02i.txt',s,s))
sub_data = read.table(sub_file, header = T, sep = ",")
rawdata = rbind(rawdata, sub_data)
}
rawdata = rawdata[complete.cases(rawdata),]
rawdata$accuracy = (rawdata$choice == rawdata$correct) * 1.0
acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
ns = 10
data_dir = '_data/RL_raw_data'
rawdata = c();
for (s in 1:ns) {
sub_file = file.path(data_dir, sprintf('sub%02i/raw_data_sub%02i.txt',s,s))
sub_data = read.table(sub_file, header = T, sep = ",")
rawdata = rbind(rawdata, sub_data)
}
rawdata = rawdata[complete.cases(rawdata),]
rawdata$accuracy = (rawdata$choice == rawdata$correct) * 1.0
acc_mean = aggregate(rawdata$accuracy, by = list(rawdata$subjID), mean)[,2]
library(ggplot2)
myconfig <- theme_bw(base_size = 20) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank() )
# scatter plot
g1 <- ggplot(df, aes(IQ,acc))
g1 <- g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.95)
g1 <- g1 + myconfig + labs(x = 'IQ', y = 'Choice accuracy (%)')
# add the regression line
g1 <- g1 + geom_smooth(method = "lm", se = T, colour='skyblue3')
g1
df
head(df)
head(df, 8)
tail(df)
tail(df, 8)
colnames(df)
row(df)
rownames(df)
#------------------------------------------------------------------------------
# one sample t-test , to test if 'acc' is above chance level
t.test(df$acc, mu = 0.5)
cor.test(df$IQ, df$acc)
#install.packages("ggplot2")
library(ggplot)
library(ggplot2)
myconfig <- theme_bw(base_size = 20) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank() )
graphics.off()
g1 <- ggplot(df, aes(IQ,acc))
g1
g1 <- g1 + geom_jitter(width=0.0, height=0.0, size=5, colour='skyblue', alpha=0.95)
g1
g1 <- g1 + myconfig + labs(x = 'IQ', y = 'Choice accuracy (%)')
1
g1
g1 <- g1 + geom_smooth(method = "lm", se = T, colour='skyblue3')
g1
clc
diag_ma
library(rstan)
lookup(diag)
m = rnorm(3,1)
m
m = rnorm(3,2)
m
m = as.matrix(rnorm(12) ,3,4)
m
m = as.matrix(rnorm(12) ,c(3,4))
m
?as.matrix
m = as.matrix(rnorm(12),3,4))
m = as.matrix(rnorm(12),3,4)
m
rnorm(12)
m = matrix(rnorm(12),3,4)
m
diag(m)
m
m = round(m)
m
m = round(m.1)
m = round(matrix(rnorm(12),3,4),1)
m
m
diag(m)
2 changes: 1 addition & 1 deletion 01.R_basics/.Rproj.user/E5E84BA0/console06/INDEX001
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n\n\n\n\n\n\n","caption":"Terminal 1","channel_id":"6076","channel_mode":1,"child_procs":false,"cols":103,"cwd":"","exit_code":15,"handle":"A9888C92","interaction_mode":2,"max_output_lines":1000,"restarted":true,"rows":11,"shell_type":1,"show_on_output":false,"terminal_sequence":1,"title":":/e/teaching/RL_R_Tromso_2018/R_intro_workshop/01.R_basics","track_env":false,"zombie":false}]
[{"allow_restart":true,"alt_buffer":false,"autoclose":1,"buffered_output":"\n\n\n\n\n\n\n\n","caption":"Terminal 1","channel_id":"6076","channel_mode":1,"child_procs":false,"cols":103,"cwd":"","exit_code":15,"handle":"A9888C92","interaction_mode":2,"max_output_lines":1000,"restarted":true,"rows":11,"shell_type":1,"show_on_output":false,"terminal_sequence":1,"title":":/e/teaching/RL_R_Tromso_2018/R_intro_workshop/01.R_basics","track_env":false,"zombie":false}]
4 changes: 2 additions & 2 deletions 01.R_basics/.Rproj.user/E5E84BA0/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"left" : {
"panelheight" : 638,
"splitterpos" : 271,
"splitterpos" : 333,
"topwindowstate" : "HIDE",
"windowheight" : 676
},
"right" : {
"panelheight" : 1118,
"splitterpos" : 701,
"splitterpos" : 1008,
"topwindowstate" : "NORMAL",
"windowheight" : 1156
}
Expand Down
2 changes: 1 addition & 1 deletion 01.R_basics/.Rproj.user/E5E84BA0/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"TabSet1" : 0,
"TabSet2" : 0,
"TabSet2" : 3,
"TabZoom" : {
}
}

0 comments on commit 9879bd9

Please sign in to comment.