Coursera Statistics One Assignment Week 1

Working memory training is a rapidly growing market with potential to further expand in the future. Several computerized software
programs promoting cognitive improvements have been developed in recent years, with controversial results and implications.

In a distinct literature, aerobic exercise has been shown to broadly enhance cognitive functions, in humans and animals. My
research group is attempting to bring together these TWO (2) trends of research, leading to an emerging third approach: designed
sports training. Specifically designed sports - wrestling, fencing, martial arts - which tax working memory by incorporating
motion in three-dimensional space, are an optimal way to combine the benefits of traditional cognitive training and aerobic
exercise into a single activity.

So, suppose we conducted a training experiment in which subjects were randomly assigned to one of two conditions:

1. Designed sports training (des)
2. Aerobic training (aer)

Also, assume that we measured both verbal (wm.v) and spatial (wm.s) working memory capacity before (pre) and after (post)
training, using TWO (2) separate measures: 1. wm.v 2. wm.s

Fictional data are available in the file: DAA.01.txt (Right click on link to save the file to your computer.)

Write an R script that does the following:

1. Plots histograms for all variables (therefore 8 histograms)
2. Provides descriptive statistics for all variables

Then, based on the R output, answer the following 5 questions (omitted):

library(psych)

#
# |------------------------------------------------------------------------------------------|
# | I N I T I A L I Z A T I O N |
# |------------------------------------------------------------------------------------------|
Init <- function(fileStr, workDirStr = "C:/Users/denbrige/100 FxOption/103 FxOptionVerBack/080 Fx Git/R-nonsource") {
    setwd(workDirStr)
    retDfr <- read.table(fileStr, header = T)
    return(retDfr)
}

#
# |------------------------------------------------------------------------------------------|
# | M A I N P R O C E D U R E |
# |------------------------------------------------------------------------------------------|

# --- Init loading raw data
wmtDfr <- Init("DAA.01.txt")

# --- Count of raw data
nrow(wmtDfr)
## [1] 200

# --- Names of header
wmtNameStr <- names(wmtDfr)

# --- Split raw data into TWO (2) data frames, omit first column
desDfr <- wmtDfr[wmtDfr$cond == "des", 2:5]
aerDfr <- wmtDfr[wmtDfr$cond == "aer", 2:5]

# --- Sum of TWO (2) data frames should equal count
nrow(desDfr) + nrow(aerDfr)
## [1] 200

# --- Layout
layout(matrix(1:16, 4, 4, byrow = TRUE))

# --- Custom Plot
for (nameStr in names(desDfr)) {
    # --- Check for normality p>0.05 is normal
    p <- shapiro.test(desDfr[[nameStr]])$p.value
    hist(desDfr[[nameStr]], prob = T, main = c(paste("DES", nameStr), paste("Shapiro p=", 
        prettyNum(p, digits = 2))), xlab = nameStr, xlim = c(0, 50))
    lines(density(desDfr[[nameStr]]))
    # --- Check for normality
    qqnorm(desDfr[[nameStr]])
}

for (nameStr in names(aerDfr)) {
    # --- Check for normality p>0.05 is normal
    p <- shapiro.test(desDfr[[nameStr]])$p.value
    hist(aerDfr[[nameStr]], prob = T, main = c(paste("AER", nameStr), paste("Shapiro p=", 
        prettyNum(p, digits = 2))), xlab = nameStr, xlim = c(0, 50))
    lines(density(aerDfr[[nameStr]]))
    # --- Check for normality
    qqnorm(desDfr[[nameStr]])
}

plot of chunk unnamed-chunk-1

describe(desDfr)
##           var   n  mean    sd median trimmed   mad min max range  skew
## pre.wm.s    1 100 18.07  3.13   18.0   18.06  2.97  10  26    16 -0.08
## post.wm.s   2 100 23.06  4.14   23.0   23.10  4.45  11  33    22 -0.06
## pre.wm.v    3 100 16.44  8.65   16.0   15.96  8.90   0  45    45  0.58
## post.wm.v   4 100 18.02 12.20   16.5   17.38 11.86   0  52    52  0.43
##           kurtosis   se
## pre.wm.s      0.01 0.31
## post.wm.s     0.08 0.41
## pre.wm.v      0.47 0.87
## post.wm.v    -0.34 1.22
describe(aerDfr)
##           var   n  mean    sd median trimmed   mad min max range  skew
## pre.wm.s    1 100 15.81  6.03     17   16.64  4.45   1  25    24 -1.26
## post.wm.s   2 100 23.30  5.64     23   23.66  5.93  11  37    26 -0.42
## pre.wm.v    3 100 14.01  9.08     13   13.55  8.90   0  36    36  0.44
## post.wm.v   4 100 16.92 11.96     16   16.50 13.34   0  43    43  0.24
##           kurtosis   se
## pre.wm.s      0.66 0.60
## post.wm.s    -0.20 0.56
## pre.wm.v     -0.39 0.91
## post.wm.v    -1.01 1.20