f=sample(foil_list,n_foils) # sesh hold the list of word-number pairs for this session sesh=list() # word count, foil count, initialized at 1 (so we can use it as an index) wc=1 fc=1 # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } # add this session's word list to the overall list nlist[[n]]=sesh } wlist=list() for(n in 1:6){ wordgroup=wordlist[words_i_general(n, words_per_session, overlap),] w=list() for(row in 1:nrow(wordgroup)){ w[[row]]=unlist(list(wordgroup[row,]$words,wordgroup[row,]$match)) } wlist[[n]]=w } examlist=list() for(row in words_i_final_exam(words_per_session, overlap)){ examlist[[row]]=unlist(list(wordlist[row,]$words,wordlist[row,]$match)) } View(examlist) View(wlist) #change starting point from 1 to 24 words_i_final_exam=function(words_per_session,overlap){ 24:(23+(6-1)*(words_per_session-overlap)+words_per_session) } words_per_session=15 overlap=5 # the number list which holds all the word-number pairs we'll want nlist=list() n_words=15 n_foils=15 # for each session for(n in 1:6){ # words, gets the words for this session w=wordlist[words_i_general(n, words_per_session, overlap),]$match # foils, gets random foils for this session f=sample(foil_list,n_foils) # sesh hold the list of word-number pairs for this session sesh=list() # word count, foil count, initialized at 1 (so we can use it as an index) wc=1 fc=1 # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } # add this session's word list to the overall list nlist[[n]]=sesh } wlist=list() for(n in 1:6){ wordgroup=wordlist[words_i_general(n, words_per_session, overlap),] w=list() for(row in 1:nrow(wordgroup)){ w[[row]]=unlist(list(wordgroup[row,]$words,wordgroup[row,]$match)) } wlist[[n]]=w } examlist=list() for(row in words_i_final_exam(words_per_session, overlap)){ examlist[[row]]=unlist(list(wordlist[row,]$words,wordlist[row,]$match)) } View(examlist) View(foils) View(nlist) write(toJSON(nlist),"nlist.json") write(toJSON(wlist),"wlist.json") write(toJSON(examlist),"examlist.json") library(jsonlite) write(toJSON(nlist),"nlist.json") write(toJSON(wlist),"wlist.json") write(toJSON(examlist),"examlist.json") View(nlist) n_words=10 n_foils=10 for(n in 1:6){ # words, gets the words for this session w=wordlist[words_i_general(n, words_per_session, overlap),]$match # foils, gets random foils for this session f=sample(foil_list,n_foils) # sesh hold the list of word-number pairs for this session sesh=list() # word count, foil count, initialized at 1 (so we can use it as an index) wc=1 fc=1 # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } View(nlist) # add this session's word list to the overall list nlist[[n]]=sesh View(nlist) View(nlist) View(nlist) # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } # add this session's word list to the overall list nlist[[n]]=sesh View(nlist) n_words=15 n_foils=15 # for each session for(n in 1:6){ # words, gets the words for this session w=wordlist[words_i_general(n, words_per_session, overlap),]$match # foils, gets random foils for this session f=sample(foil_list,n_foils) # sesh hold the list of word-number pairs for this session sesh=list() # word count, foil count, initialized at 1 (so we can use it as an index) wc=1 fc=1 # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } # add this session's word list to the overall list nlist[[n]]=sesh } View(nlist) n_words=10 n_foils=10 # for each session for(n in 1:6){ # words, gets the words for this session w=wordlist[words_i_general(n, words_per_session, overlap),]$match # foils, gets random foils for this session f=sample(foil_list,n_foils) # sesh hold the list of word-number pairs for this session sesh=list() # word count, foil count, initialized at 1 (so we can use it as an index) wc=1 fc=1 # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } # add this session's word list to the overall list nlist[[n]]=sesh } wlist=list() for(n in 1:6){ wordgroup=wordlist[words_i_general(n, words_per_session, overlap),] w=list() for(row in 1:nrow(wordgroup)){ w[[row]]=unlist(list(wordgroup[row,]$words,wordgroup[row,]$match)) } wlist[[n]]=w } View(nlist) library(jsonlite) getwd() setwd("C:/Users/Jeri/oTree") # this reads in the ratpal list and exports a formatted csv rm(list = ls()) # ratpal=read.csv(file.choose(),header=FALSE) ratpal=read.csv("RAT items.csv",header=FALSE,stringsAsFactors = F) # remove the entry with 2 answers # (high/district/house) ratpal=data.frame(ratpal[1:nrow(ratpal)!=20,]) wordlist=data.frame(words=character(),match=character(),stringsAsFactors = F) wordpairs=vector("list",nrow(ratpal)) numpairs=vector("list",nrow(ratpal)) for(r in 1:nrow(ratpal)){ # get each row of the ratpal words and format it row=ratpal[r,] r2=unlist(strsplit(as.character(row)," ")) # get the words (r3[1:(length(r3)-1)]) and the match (r3[length(r3)]) r3=(r2[1:(length(r2)-10)]) match=r3[length(r3)] words=paste(r3[1:(length(r3)-1)],collapse = '') # add them to a df wordlist wordlist=rbind(wordlist,data.frame(words,match)) # wordpairs[[r]]=(list(words,match)) # numpairs[[r]]=(list(round(runif(1,1,9)),match)) } foils=read.csv("ratpal_foils.csv",header=FALSE,stringsAsFactors = F) foil_list=unlist(lapply(foils$V2,tolower)) library(jsonlite) getwd() setwd("C:/Users/Jeri/oTree") # this reads in the ratpal list and exports a formatted csv rm(list = ls()) # ratpal=read.csv(file.choose(),header=FALSE) ratpal=read.csv("RAT items.csv",header=FALSE,stringsAsFactors = F) # remove the entry with 2 answers # (high/district/house) ratpal=data.frame(ratpal[1:nrow(ratpal)!=20,]) wordlist=data.frame(words=character(),match=character(),stringsAsFactors = F) wordpairs=vector("list",nrow(ratpal)) numpairs=vector("list",nrow(ratpal)) for(r in 1:nrow(ratpal)){ # get each row of the ratpal words and format it row=ratpal[r,] r2=unlist(strsplit(as.character(row)," ")) # get the words (r3[1:(length(r3)-1)]) and the match (r3[length(r3)]) r3=(r2[1:(length(r2)-10)]) match=r3[length(r3)] words=paste(r3[1:(length(r3)-1)],collapse = '') # add them to a df wordlist wordlist=rbind(wordlist,data.frame(words,match)) # wordpairs[[r]]=(list(words,match)) # numpairs[[r]]=(list(round(runif(1,1,9)),match)) } foils=read.csv("ratpal_foils.csv",header=FALSE,stringsAsFactors = F) foil_list=unlist(lapply(foils$V2,tolower)) # remove from the list of foils any words which overlap between foils and match words foil_list= foil_list[ unlist(lapply( foil_list,function(x){ !(x %in% intersect(wordlist$match,foil_list)) } )) ] # change the data types of the columns from factor to characters wordlist$words=as.character(wordlist$words) wordlist$match=as.character(wordlist$match) #change above code to start at word #24 (start with 50% or less solving in 15 sec) words_i=function(sesh){ if(sesh==1){ 24:38 } else{ (sesh-2)*10+34:48 } } #change starting point from 1 to 24 words_i_general=function(sesh,words_per_session,overlap){ (sesh-1)*(words_per_session-overlap)+24:(23+words_per_session) } #change starting point from 1 to 24 words_i_final_exam=function(words_per_session,overlap){ 24:(23+(6-1)*(words_per_session-overlap)+words_per_session) } words_per_session=15 overlap=5 # the number list which holds all the word-number pairs we'll want nlist=list() n_words=10 n_foils=10 # for each session for(n in 1:6){ # words, gets the words for this session w=wordlist[words_i_general(n, words_per_session, overlap),]$match # foils, gets random foils for this session f=sample(foil_list,n_foils) # sesh hold the list of word-number pairs for this session sesh=list() # word count, foil count, initialized at 1 (so we can use it as an index) wc=1 fc=1 # keep adding random words from either words or foils until we have # 10 words and 10 foils # each paired with a random number [1:9] while(wc=n_words+1){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else if(fc>=n_foils+1){ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } else{ if(runif(1)>.5){ sesh[[length(sesh)+1]]=c(f[fc],round(runif(1,1,9))) fc=fc+1 } else{ sesh[[length(sesh)+1]]=c(w[wc],round(runif(1,1,9))) wc=wc+1 } } } # add this session's word list to the overall list nlist[[n]]=sesh } wlist=list() for(n in 1:6){ wordgroup=wordlist[words_i_general(n, words_per_session, overlap),] w=list() for(row in 1:nrow(wordgroup)){ w[[row]]=unlist(list(wordgroup[row,]$words,wordgroup[row,]$match)) } wlist[[n]]=w } View(wlist) View(nlist) View(wlist) dat = read.csv('C:/Users/Jeri/Documents/Doctoral studies/PSY9075 Prediction Models/math achieve for centering.csv') names(dat) View(dat) reg1=lm(ma ~ SES, dat) summary(reg1) m1 = lmer(ma ~ 1 + (1|ID),dat) library(multilevel) m1 = lmer(ma ~ 1 + (1|ID),dat) library(lme4) m1 = lmer(ma ~ 1 + (1|ID),dat) summary(m1) m0 = lmer(ma ~ 1 + (1|ID),dat) #uncentered hours worked summary(m0) summary(reg1) #grand mean centering mean(dat$SES) dat$SES.grand = dat$SES-mean(dat$SES) mean(dat$SES.grand) View(dat) #for group mean centering library(data.table) setDT(dat)[, group := mean(SES), by = ID] View(dat) setDT(dat)[, group.mean := mean(SES), by = ID] View(dat) dat$SES.group = dat$SES - dat$group.mean View(dat) dat = read.csv('C:/Users/Jeri/Documents/Doctoral studies/PSY9075 Prediction Models/math achieve for centering.csv') names(dat) library(lme4) library(multilevel) #for grand mean centering mean(dat$SES) dat$SES.grand = dat$SES-mean(dat$SES) #for group mean centering library(data.table) setDT(dat)[, group.mean := mean(SES), by = ID] dat$SES.group = dat$SES - dat$group.mean #regular regression: ma on SES reg1=lm(ma ~ SES, dat) summary(reg1) reg1.grand = lm(ma ~ SES.grand, dat) summary(reg1.grand) reg1.group = lm(ma ~ SES.group, dat) summary(reg1.group) #random intercepts m0 = lmer(ma ~ 1 + (1|ID),dat) summary(m0) #random intercepts for SES m1 = lmer(ma ~ SES + (1|ID),dat) summary(m1) summary(reg1.group) summary(m1) #random intercepts for SES.grand m1.grand = lmer(ma ~ SES.grand + (1|ID),dat) summary(m1.grand) summary(m1) m1.group = lmer(ma ~ SES.group + (1|ID),dat) summary(m1.group) summary(m1) summary(m1.grand) summary(m1.group) m1gp = lmer(ma ~ SES + group.mean + (1|ID),dat) summary(m1gp) m1gp.grand = lmer(ma ~ SES.grand + group.mean + (1|ID),dat) summary(m1gp.grand) m1gp.group = lmer(ma ~ SES.group + group.mean + (1|ID),dat) summary(m1gp.group) #random intercepts and slopes for SES m1r = lmer(ma ~ SES + (1 + SES|ID),dat) summary(m1r) #random intercepts and slopes for SES m1r = lmer(ma ~ SES + (SES + 1|ID),dat) summary(m1r) #random intercepts and slopes for SES m1r = lmer(ma ~ SES + (1 + SES|ID),dat) summary(m1r) summary(m1gp.group) summary(m1r) #random intercepts and slopes for SES.grand m1r.grand = lmer(ma ~ SES.grand + (1 + SES.grand|ID),dat) summary(m1r.grand) #random intercepts and slopes for SES.group m1r.group = lmer(ma ~ SES.group + (1 + SES.group|ID),dat) summary(m1r.group) #adding group mean to model #random intercepts and slopes for SES and group mean m1rgp = lmer(ma ~ SES + group.mean + (1 + SES|ID),dat) summary(m1rgp) #random intercepts and slopes for SES.grand and group mean m1rgp.grand = lmer(ma ~ SES.grand + group.mean + (1 + SES.grand|ID),dat) summary(m1rgp.grand) #random intercepts and slopes for SES.group and group mean m1rgp.group = lmer(ma ~ SES.group + group.mean + (1 + SES.group|ID),dat) summary(m1rgp.group) #fixed effects model (from TJ's formula) reg1.fixed = lm(ma ~ 0 + factor(ID) + SES, dat) summary(reg1.fixed)