Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

solve using r studio: a) Create a normally distributed population of 100000 case

ID: 3309817 • Letter: S

Question

solve using r studio:

a) Create a normally distributed population of 100000 cases with a mean of 80 and a standard deviation of 15, and call it 'pop'.

b) Take a sample of size N = 15 (without replacement) from the population, and call it 'samp'.

c) Pretend to give your sample an intervention. More specifically, add a normally distributed variable with a mean of 7 and standard deviation of 5 (call it 'pop2') to your sample ('samp'). Call this new variable 'inter_samp'.

d) Use null hypothesis testing (all steps, a = 01) to determine if the fake intervention was effective at increasing scores. Be sure to Interpret (even If It Is purely subjective) the effect site and confidence interval width, and include a general summary of the results

Explanation / Answer

#Random sample 100000
pop <- rnorm(100000, mean = 80, sd=15)

#sample of 15 from pop
samp <- sample(pop, 15)

#generate one sample with mean=7 and sd=5
pop2 <- rnorm(1, mean = 7, sd=5)

#combine pop2 and samp
inter_samp <- c(samp, pop2)

#null hypothesis H0:mu= mu0; Ha: mu > mu0
t.test.right <- function(data, mu0, alpha)
{
t.stat <- (mean(data) - mu0) / (sqrt(var(data) / length(data)))
dof <- length(data) - 1
t.critical <- qt(1-alpha, df= dof) #Es alpha 0.05 -> 1.64 (df=Inf)
p.value <- 1 - pt(t.stat, df= dof)
  
if(t.stat > t.critical)
{
print("Reject H0")
}
else
{
print("Accept H0")
}
print('T statistic')
print(t.stat)
print('T critical value')
print(t.critical)
print('P value')
print(p.value)
  
return(t.stat)
}
t.test.right(inter_samp, mu0 = 80, alpha = 0.01)


#summary
summary(inter_samp)

#confidence interval
error <- qt(0.995, df=length(inter_samp)-1)*sd(inter_samp)/sqrt(length(inter_samp))
error

#left tail
left <- mean(inter_samp)-error
left
# right tail
right <- mean(inter_samp)+error
right

Output:

> pop <- rnorm(100000, mean = 80, sd=15)
> samp <- sample(pop, 15)
> pop2 <- rnorm(1, mean = 7, sd=5)
> inter_samp <- c(samp, pop2)
> t.test.right <- function(data, mu0, alpha)
+ {
+ t.stat <- (mean(data) - mu0) / (sqrt(var(data) / length(data)))
+ dof <- length(data) - 1
+ t.critical <- qt(1-alpha, df= dof) #Es alpha 0.05 -> 1.64 (df=Inf)
+ p.value <- 1 - pt(t.stat, df= dof)
+   
+ if(t.stat > t.critical)
+ {
+ print("Reject H0")
+ }
+ else
+ {
+ print("Accept H0")
+ }
+ print('T statistic')
+ print(t.stat)
+ print('T critical value')
+ print(t.critical)
+ print('P value')
+ print(p.value)
+   
+ return(t.stat)
+ }
> t.test.right(inter_samp, mu0 = 80, alpha = 0.01)
[1] "Accept H0"
[1] "T statistic"
[1] -3.002541
[1] "T critical value"
[1] 2.60248
[1] "P value"
[1] 0.9955368
[1] -3.002541
> summary(inter_samp)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.5175 57.9300 66.8800 63.7700 74.5200 91.6400
> error <- qt(0.995, df=length(inter_samp)-1)*sd(inter_samp)/sqrt(length(inter_samp))
> error
[1] 15.92934
> left <- mean(inter_samp)-error
> left
[1] 47.83952
> right <- mean(inter_samp)+error
> right
[1] 79.6982