library(whoppeR)
library(tidyr)
library(reshape2)
library(ggplot2)
library(dplyr)
library(FAM)
library(grid)
library(gridExtra)
library(pander)
library(wesanderson)
knitr::opts_chunk$set(echo = FALSE,fig.width=11,fig.height=7,cache=FALSE, 
               warning=F, message=FALSE, fig.align='center')
labels<-function(x,y) {
  half_list <- list('1' = "First Half Cues", '2'="Second Half Cues")
  prac_type_list<- list('C' = 'No Practice', 'S' = 'Study', 'T' = 'Test')
  if (x=='half') {
    return(half_list[y])
  } else if (x=='prac_type') {
    return(prac_type_list[y])
  } else {
    return(y)
  }
}

my_scale <- scale_fill_brewer("Other Cue\nPractice Type",
                              breaks= c("none","C", "S","T"),
                              labels = c("No Other Cue", "No Practice", "Study","Test"),
                              guide = guide_legend(keyheight = unit(1,'cm')),
                              palette="Set1")

Grand Average Performance

subject_means <- badSubs(SCKT_allSs)$means
sub_means_plot <- ggplot(badSubs(SCKT_allSs)$means,
                         aes(prac_acc,final_acc)) +
  geom_point(size=4) +
  geom_point(size =4, shape =25, fill = "red",
             aes(x=mean(prac_acc),y=mean(final_acc,na.rm=T))) + 
  scale_x_continuous("Practice Test Accuracy",limits=c(0,1)) +
  ylab("Final Test Accuracy") +
  theme_larger() +
  ggtitle("Average Performace by Subject")

print(sub_means_plot)

Cluster Analysis

Single Linkage Heirarchical Clustersing based on Euclidian Distance

clusters <- findSubjectClusters(SCKT_allSs, cut= 4)
clusters$cluster[,] <- lapply(clusters$cluster,factor)
SCKT_allSs <- left_join(SCKT_allSs, clusters$cluster)
plot(clusters$tree)

IV analysis

IVxSS <- IVsummary(SCKT_allSs,
                   grouping.vars =c("subject","half","practice","other_type"))
IV <- IVsummary(SCKT_allSs,
                grouping.vars =c("half","practice","other_type"))

IVplot <- ggplot(mutate(IV, other_type = as.character(other_type) %>%
                              replace(is.na(.), "none")),
             aes(x=practice,y=final_score,fill=other_type)) +
  geom_bar(position='dodge',stat="identity",drop=F) +
  facet_grid(~ half, labeller = label_both) +
  ylab("Final Test Accuracy") +
  scale_fill_manual("Other Cue\nPractice Type",
                    breaks= c("none","C", "S","T"),
                    labels = c("No Other Cue", "No Practice", "Study","Test"),
                    guide = guide_legend(keyheight = unit(1,'cm')),
                    values=wes_palette("Darjeeling")) + 
  scale_x_discrete("Cue Practice",
                   labels = c(C="No Practice",S="Study",`T` = "Test")) + 
  theme(strip.text.x = element_text(size = 20),
        legend.key.height=unit(2,"line")) +
  ggtitle('Final Test Accuracy')
IVplot 
aov.1 <- aov(final_score~(half*practice*other_type) + 
               Error(subject/(half*practice*other_type)),
             data=IVxSS)
pander(summary(aov.1),style = 'simple',justify='left',table.split.table=Inf)
IV_half_prac <- IVsummary(SCKT_allSs, grouping.vars =c("half","practice"),
                          fn=c("mean"))  
#   select(-prac_score_sd,sd=final_score_sd) %>%
#   mutate(CI_range = sd/(sqrt(n)*qt(.975,n-1)))
half_prac_plot <- IVplot %+% IV_half_prac +
  aes(x=practice,y=final_score, fill= NULL)
half_prac_plot
aov2.data <- SCKT_allSs %>% filter(repeating=='N') %>%
  group_by(subject,half, practice, other_type) %>%
  summarise(final_score = mean(final_score))
aov.2 <- aov(final_score~(half*practice)+Error(subject/(half*practice)),
             data=aov2.data)
pander(summary(aov.1),justify='left',table.split.table=Inf)

Conditional Analysis

# SCKT_allSs$prac_score <- factor(SCKT_allSs$prac_score)

# selected only tested cue/targets pairs
condData <- SCKT_condSummary(SCKT_allSs)

condPlot <- ggplot(mutate(condData$group,
                          prac_score = replace(prac_score,is.na(prac_score),-1)) %>%
                     recode_other_type(),
                   aes(x=practice,y=final_acc,fill=factor(prac_score))) +
  geom_bar(position='dodge',stat="identity",drop=F) +
  facet_grid(other_type~half,
             labeller = labeller(half=label_both,
                                 other_type = c('Tneg'='Tested: Incorrect',
                                                'Tplus'='Tested: Correct',
                                                "S"="Studied",
                                                "C" = "No Practice"))) +
  scale_fill_manual("Practice Test",
                    labels=c("Not Tested", "Incorrect" ,"Correct"),
                    values = wes_palette("FantasticFox")) + 
  ylab("Final Test Accuracy")
condPlot
jointData <- SCKT_jointSummary(SCKT_allSs)


wjhopper/FAM documentation built on May 4, 2019, 7:33 a.m.