0323 HW4-5
HW Exercise 0323-4
The following zip file contains one subject’s laser-event potentials (LEP) data for 4 separate conditions (different level of stimulus intensity), each in a plain text file (1w.dat, 2w.dat, 3w.dat and 4w.dat). The rows are time points from -100 to 800 ms sampled at 2 ms per record. The columns are channel IDs. Input all the files into R for graphical exploration.
unzip data, create a list for these 4 dataset and assign the column name
m<-unzip("C:/Users/USER/Downloads/Subject1.zip", exdir="C:/Users/USER/Documents")
temp = list.files("C:/Users/USER/Documents/Subject1", pattern="*.dat", full.names=TRUE)
header<-scan("C:/Users/USER/Documents/Subject1/1w.dat", skip=1, sep="\t", nlines = 1, what = "character")
myfile<-lapply(temp, read.table, skip=2, sep="\t",header=FALSE, na.strings=c("", "NA") ,fill=TRUE)
myfile[[1]]$V31<-NULL
myfile[[2]]$V31<-NULL
myfile[[3]]$V31<-NULL
myfile[[4]]$V31<-NULL
newheader<-header[-31]
subject<-lapply(myfile, setNames, nm=newheader )graphical exploration
subject_df <- rbind(subject[[1]], subject[[2]], subject[[3]], subject[[4]])
subject_df$scenario<-rep(paste0(1:4, "w"), each=nrow(subject[[1]]))
subject_df$time<-rep(seq(-100, 800, 2), 4)
library("reshape2")
library("ggplot2")## Warning: package 'ggplot2' was built under R version 3.6.3
dat.melt <- melt(subject_df, id = c("time", "scenario"))
ggplot(dat.melt, aes(x = time, y =value, colour=as.factor(scenario)))+
geom_line(data=subset(dat.melt, variable==as.factor(variable)), aes(colour=as.factor(scenario)), size=1)+
facet_wrap(~variable,nrow=5)+
xlab("Time")+
ylab("LFP")+
theme(legend.title = element_blank())HW Exercise 0323-5
The ASCII (plain text) file schiz.asc contains response times (in milliseconds) for 11 non-schizophrenics and 6 schizophrenics (30 measurements for each person). Summarize and compare descriptive statistics of the measurements from the two groups. Source: Belin, T., & Rubin, D. (1995). The analysis of repeated-measures data on schizophrenic reaction times using mixture models. Statistics in Medicine 14(8), 747-768.
read the data and check structure
create variables
Long format
## Warning: package 'reshape' was built under R version 3.6.3
##
## Attaching package: 'reshape'
## The following objects are masked from 'package:reshape2':
##
## colsplit, melt, recast
average RT for each subject
## dtalong$ID dtalong$RT
## 1 1 311.0667
## 2 2 366.6667
## 3 3 306.2000
## 4 4 303.6000
## 5 5 265.2000
## 6 6 339.8000
## 7 7 358.1333
## 8 8 268.4667
## 9 9 257.7333
## 10 10 325.6667
## 11 11 309.3333
## 12 12 303.5333
## 13 13 419.0667
## 14 14 635.8667
## 15 15 599.8667
## 16 16 594.3333
## 17 17 488.5333
box plot
ANOVA
##
## Error: ID
## Df Sum Sq Mean Sq
## schiz 1 3503780 3503780
##
## Error: ID:time
## Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 29 1232036 42484
##
## Error: Within
## Df Sum Sq Mean Sq F value Pr(>F)
## schiz 1 1042372 1042372 39.92 6.05e-10 ***
## Residuals 478 12479824 26108
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1