options(digits=5,width=70) # R console display parameters
options(contrasts=c("contr.sum","contr.poly") )
# install.packages("BSDA")
library(BSDA) # use this for z.test()
Answer the questions in Section 2 and submit your answers as a script file on Avenue 2 Learn. Make sure to begin your script file with the following lines:
# PSYCH 710 Lab 2 Homework
# Date: 15-SEP-2022
# Your Name: <<Your name here>>
# Student ID: <<Your ID here>>
# Collaborators: <<Names of your collaborators here>>
Also, make sure that text that is not an R command is preceded by a comment symbol (#). For example, you can insert questions or comments among your commands like this:
# The following command doesn't work... not sure why...
# ttest(x=g1,y=g2) # was trying to do a t test
set.seed(210980) # set random number seed
dscores <- rnorm(n=20,5,10) # get the values
Calculate the mean, variance, and standard deviation of
dscores
. Use a boxplot
to display the
distribution of values.
Use a quantile-quantile plot to investigate whether the
dscores
is distributed normally. Do the data
look approximately normal? Use
shapiro.test
to address this question with a quantitative
test.
Imagine that we conducted an experiment that evaluated the effect
of a drug on memory. Twenty participants completed a standardized memory
test before and after taking the drug. The difference scores on the two
memory tests (post-drug minus pre-drug) are stored in
dscores
. Use a \(t\) to
evaluate the hypothesis that memory was affected (positively
or negatively) by the drug. State the null and
alternative hypotheses evaluated by your test, and whether or not you
reject the null hypothesis.
Use z.test
to repeat the analysis performed in
question 3 with a \(z\) test. To use
z.test
, you need to set sigma.x
to a value
that equals the population standard deviation (\(\sigma\)) of dscores
. Although
we do not know \(\sigma\), we
can estimate it with the sample standard deviation,
sigma.x = sd(dscores)
. Perform the \(z\) test this way. How do the results
differ from the \(t\) test in question
4? Why do they differ? Which test do you think is more valid?
We believe that the drug will improve memory. Use a one-sided \(t\) test to evaluate this idea. Clearly state the null and alternative hypotheses, the \(t\) and \(p\) values, and your conclusion regarding the null hypothesis.