# Import the necessary libraries library("psych") # Raw data shoePrices <- c(60,70,75,55,80,55,50,40,80,70,50,95,120,90,75,85,80,60,110,65,80,85,85,45,75,60,90,90,60,95,110,85,45,90,70,70) mu <- 80 # population mean sPricesM <- mean(shoePrices) # Mean shoe prices sigma <- 19.2 # population SD alpha <- 0.10 # level of significance n <- 36 # sample size # Z test ztest <- (sPricesM - mu)/(sigma/sqrt(n)) ztest # Finding critical value for alpha = 0.05 two-tailed test cv <- qnorm(alpha, mean = 0, sd = 1, lower.tail = TRUE) cv # presented data mu <- 16.3 # avg population x <- 17.7 # avg sample s <- 1.8 # sd sample n <- 10 # sample size df <- n-1 # dof alpha <- 0.05 # t test ttest <- (x - mu)/(s/sqrt(n)) round(ttest,3) cv <- qt(alpha/2, df) round(cv*c(1,-1),3) # critical values # Presented data x1 <- 88.42 # avg sample 1 x2 <- 80.61 # avg sample 2 sigma1 <- 5.62 # sd population 1 sigma2 <- 4.83 # sd population 2 n1 <- 50 # sample size 1 n2 <- n1 # sample size 2 alpha <- 0.05 # sig. level # Calculating Z test ztest <- ((x1-x2) - 0) / sqrt((sigma1^2/n1) + (sigma2^2/n2)) round(ztest,3) # Finding critical value for two-tailed test cv <- qnorm(alpha/2, mean=0, sd = 1) round(cv*c(1,-1),3) # Presented data x1 <- 191 x2 <- 199 n1 <- 8 n2 <- 10 s1 <- 38 s2 <- 12 alpha <- 0.05 df1 <- n1-1 df2 <- n2-1 # Performing t test ttest <- ((x1-x2) - 0) / sqrt((s1^2/n1) + (s2^2/n2)) round(ttest,3) # Calculating critical value if (df1 < df2) {df <- df1} else {df <- df2} cv <- qt(alpha/2,df) round(cv*c(1,-1),3) # Raw data prior <- c(210,235,208,190,172,244) after <- c(190,170,210,188,173,228) n <- 6 # sample size df <- n-1 # dof alpha <- 0.1 # sig level # Calculated data dM <- mean(prior-after) # avg of differences sD <- sd(prior-after) # sd of differences # Statistical test ttest <- (dM - 0)/(sD/sqrt(n)) round(ttest,3) # Critical value cv <- qt(alpha/2,df) round(cv*c(1,-1),3)