In: Math
Before opening the dataset needed for this problem, you’ll need to call the “car” package:
> library(car)
Now you can import the “Wong” dataset and use it to answer the question below.
Remember to include any code you use along with your answers in your submission!
3. The Wong dataset contains data from a study by Wong, Monette,
and Weiner (2001) on patients who fell into comas after sustaining
traumatic brain injuries. After waking, Wong and colleagues
administered two different intelligence tests (the “piq” and “viq”
variables). The “duration” variable indicates how long each patient
was in a coma before waking (measured in days).
a. Consider that this dataset represents the population of all
patients who fell into comasafter sustaining traumatic brain
injuries. Calculate the population mean and standard deviation of
the duration variable.
b. Simulate drawing 1,000 random samples of size n =30 and store
the sample mean durations in a vector (see the Lab 4 handout and/or
video). Create a histogram of your sampling distribution of means
for duration.
c. Calculate the mean and standard deviation of your sampling
distribution. How do they compare to the population mean and
standard deviation?
d. If you decreased your sample size to n=10, how would the shape
of your sampling distribution change compared to what you reported
above?
The code for the following question is given below:
A.) Code:
#calling the library
library(car)
set.seed(12)
#Loading the data
data<-Wong
data
#A.)selecting the "duration variable"
dur<-data$duration
dur
##Population mean and standard deviation
mean(dur)
sd(dur)
Output:
> mean(dur)
[1] 14.29607
> sd(dur)
[1] 26.03989
B.) Code:
#B.) 1000 samples of size n=30
l<-list()
m<-c()
s<-c()
for(i in 1:1000){
l[[i]]<-sample(dur,30,replace = F)
m[i]<-mean(l[[i]])
s[i]<-sd(l[[i]])
}
#Creating histogram for sample mean
hist((m)
Output: C.) Code:C.) Code:
#C.) Mean and standard deviation of sampling distribution
mean(m)
sd(m)
Output:
> mean(m)
[1] 14.32873
> sd(m)
[1] 4.494283
D.) Code:
##D.)Changing the sample size to 10
l1<-list()
m1<-c()
s1<-c()
for(i in 1:1000){
l1[[i]]<-sample(dur,10,replace = F)
m1[i]<-mean(l1[[i]])
s1[i]<-sd(l1[[i]])
}
#Creating histogram for sample mean
hist((m1))
Output: