getCues.R

aleph4 — Sep 19, 2012, 3:34 PM

# This script gets cues from an excel .csv containing cues & delays
# It also analyzes inital DD session from subject
# Using DD analysis, it determines an appropriate number of levels of DD task and outputs list of cues x delay x value

# Source Core analysis functions & ggplot
library(ggplot2)
source("../../R Scripts/ddAnalysisCore.R")

# Allow command arguments and take the first to be subject number
args <- commandArgs(TRUE)
sub <- args[1]
sub  <- 26
# Load DD & Cues
DD <- read.csv(paste("DD/Day1/Day1DD_",sub,".csv",sep=""))
FCues <- read.csv(paste("Selected_Cues/FCues_",sub,".csv",sep=""))
PCues <- read.csv(paste("Selected_Cues/PCUes_",sub,".csv",sep=""))

# Add condition column
PCues$condition = "past"
FCues$condition = "future"

# Remove extra columns from import
DD$X <- NULL
PCues <- PCues[,1:4]
FCues <- FCues[,1:4]

# Make combined Cues variable
Cues <- rbind(PCues,FCues)

# Get control delays
CDelays <- createControlDelays(FCues$delay,PCues$delay,1.1)

# Make data frame with all days & rename cols
Delays = as.data.frame(rbind(cbind("past", PCues$delay),cbind("future",FCues$delay),cbind("control",CDelays)))
colnames(Delays) <- c("condition","delay")

# Analyze DD Data (get DV values from trials using logistic regression)
DVs <- analyzeSubDD(DD)
Warning: glm.fit: algorithm did not converge
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred

# Get imputed values for each condition
imputedValues <- ddply(Delays,.(condition),imputeDelayValues,DVs=DVs,extra=.35)

# Cross imputed values for each condition (for each delay) with an interval num of 11
crossedValues <- ddply(imputedValues,.(condition),crossValues,num=12)

# Use write lists to output lists to disk
ddply(crossedValues,.(condition),writeLists,Cues=Cues)
[1] "Wrote Day2_Lists/control_26.txt"
Joining by: delay
[1] "Wrote Day2_Lists/future_26.txt"
Joining by: delay
[1] "Wrote Day2_Lists/past_26.txt"
data frame with 0 columns and 0 rows

# Print so user can see them in terminal
print(imputedValues)
   condition delay     DV    Low   High HighIndiff LowIndiff
1    control    12 0.9344 0.5500 0.9524      10.50     18.18
2    control    20 0.8805 0.5305 0.9524      10.50     18.85
3    control     7 0.7786 0.4286 0.9524      10.50     23.33
4    control    11 0.5844 0.2344 0.9344      10.70     42.67
5    control    15 0.3260 0.2000 0.6760      14.79     50.00
6    control    17 0.2925 0.2000 0.6425      15.56     50.00
7    control     6 0.1791 0.2000 0.5291      18.90     50.00
8     future     1 0.9903 0.5500 0.9524      10.50     18.18
9     future    12 0.9344 0.5500 0.9524      10.50     18.18
10    future     2 0.8286 0.4786 0.9524      10.50     20.89
11    future     9 0.6696 0.3196 0.9524      10.50     31.28
12    future    13 0.4151 0.2000 0.7651      13.07     50.00
13    future    16 0.3173 0.2000 0.6673      14.99     50.00
14    future     5 0.1758 0.2000 0.5258      19.02     50.00
15      past     8 0.9714 0.5500 0.9524      10.50     18.18
16      past    19 0.8982 0.5482 0.9524      10.50     18.24
17      past     4 0.7951 0.4451 0.9524      10.50     22.47
18      past    10 0.6118 0.2618 0.9524      10.50     38.19
19      past    14 0.3350 0.2000 0.6850      14.60     50.00
20      past    18 0.2771 0.2000 0.6271      15.95     50.00
21      past     3 0.1444 0.2000 0.4944      20.22     50.00

# Save diagnostics
# Make plot of smoothed fit used for subject & save plot
smoothplot <- ggplot(DVs,aes(delay,DV)) + geom_point() + stat_smooth()
smoothplot
geom_smooth: method="auto" and size of largest group is <1000, so using
loess. Use 'method = x' to change the smoothing method.

plot of chunk unnamed-chunk-1


ggsave(filename=paste("Diagnostics/Smoothplot_",sub,".png",sep=""),plot=smoothplot,width=5,height=4)
geom_smooth: method="auto" and size of largest group is <1000, so using
loess. Use 'method = x' to change the smoothing method.

# Save table of imputed values
write.table(imputedValues,file=paste("Diagnostics/imputedValues_",sub,".csv",sep=""),quote=FALSE,row.names=FALSE)