<center> # Psy202 Tutorial Week #4 July 15th 2025 ### Jennet Baumbach <img src="https://i.pinimg.com/originals/12/b1/b9/12b1b97b99b3b793ccbd13e72a8f696b.gif",height = "400" width="500"> *We will begin @ 5:10pm* --- ## Tutorial #4 Practice Problem > Joel was interested in whether a drug can improve running speed. Participants were recruited into one of four conditions: no drug, placebo, low dose, or high dose. Next, they ran a 100 meter course while being timed. Results of their time (in seconds) is below. Is there evidence to suggest the drugs affected running speed? Make sure to conduct hypotheses, assumptions, test of assumptions, a figure, and power if necessary. Discuss and interpret the results. -- .pull-left[ ``` r data <- data.frame( Score = c(1,2,3,4,5), No_Drug = c(22,20,27,30,26), Placebo = c(25,23,26,34,22), Low_Dose = c(11,23,17,19,20), High_Dose = c(15,14,18,23,25) ) ``` ] -- .pull-right[ - I would begin by typing in the values in to a software program in order to allow for computational analysis - Perhaps try solving the question BOTH by hand and using a software program! :) ] --- ## Tutorial #4 Practice Problem > Joel was interested in whether a drug can improve running speed. Participants were recruited into one of four conditions: no drug, placebo, low dose, or high dose. Next, they ran a 100 meter course while being timed. Results of their time (in seconds) is below. Is there evidence to suggest the drugs affected running speed? Make sure to conduct hypotheses, assumptions, test of assumptions, a figure, and power if necessary. Discuss and interpret the results. | Score| No_Drug| Placebo| Low_Dose| High_Dose| |-----:|-------:|-------:|--------:|---------:| | 1| 22| 25| 11| 15| | 2| 20| 23| 23| 14| | 3| 27| 26| 17| 18| | 4| 30| 34| 19| 23| | 5| 26| 22| 20| 25| |Stat | No_Drug| Placebo| Low_Dose| High_Dose| |:--------|-------:|-------:|--------:|---------:| |mean | 25| 26.0| 18| 19.0| |variance | 16| 22.5| 20| 23.5| ## Psy202 Week #4 Answer -- - I will solve the problem usin `Rstudio` -- - Compare a "by hand" computational appraoch to build-in R formula to compute ANOVA -- - First, enter the raw data: ``` r data <- data.frame( Score = c(1,2,3,4,5), No_Drug = c(22,20,27,30,26), Placebo = c(25,23,26,34,22), Low_Dose = c(11,23,17,19,20), High_Dose = c(15,14,18,23,25) ) ``` --- ## Psy202 Week #4 Answer -- **Assumptions** -- - Normality -- - Independence -- - Homogenaity of variances (test with F max) -- `$$F_{max} = \dfrac{var_{max}}{var_{min}}$$` ``` r Fmax = 23.5 / 16 Fmax ``` ``` ## [1] 1.46875 ``` -- ***Look up the critical value in the table...*** -- Fcrit = 20.6 -- .pull-left[ `$$F_{max} > F_{crit}$$` ] -- .pull-right[ Therefore the homogenaity assumption is met. ] --- ## Psy202 Week #4 Answer .pull-left[ `$$SS_{between} = n * \Sigma (\bar{X_j} - Gm)^2$$` ] .pull-right[ ``` r Grand_mean = mean(c(25,26,18,19)) ss_between = 5*((25-Grand_mean)^2 + (26-Grand_mean)^2 + (18-Grand_mean)^2+ (19-Grand_mean)^2) ss_between ``` ``` ## [1] 250 ``` ] -- .pull-left[ `$$df_{between} = k - 1$$` ] -- .pull-right[ ``` r df_between = 4-1 df_between ``` ``` ## [1] 3 ``` ] -- .pull-left[ `$$MS_{between} = \frac{SS_{between}}{df_{between}}$$` ] -- .pull-right[ ``` r MS_between = ss_between / df_between MS_between ``` ``` ## [1] 83.33333 ``` ] --- ## Psy202 Week #4 Answer .pull-left[ `$$SS_{within} = (df_{1} * var_{1}) + (df_{2} * var_{2}) \\ + (df_{3} * var_{3})$$` ] -- .pull-right[ ``` r ss_within = (4 * var(data$No_Drug)) + (4 * var(data$Placebo)) + (4 * var(data$Low_Dose) + (4 * var(data$High_Dose))) ss_within ``` ``` ## [1] 328 ``` ] -- .pull-left[ `$$df_{within} = N - k$$` ] -- .pull-right[ ``` r df_within = 20-4 df_within ``` ``` ## [1] 16 ``` ] -- .pull-left[ `$$MS_{within} = \frac{SS_{within}}{df_{within}}$$` ] -- .pull-right[ ``` r MS_within = ss_within / df_within MS_within ``` ``` ## [1] 20.5 ``` ] --- ## Psy202 Week #4 Answer -- .pull-left[ `$$F = \frac{MS_{between}} {MS_{within}}$$` ] -- .pull-right[ ``` r F = MS_between / MS_within F ``` ``` ## [1] 4.065041 ``` ] -- ``` r # Manually find critical F value for (2,18) df F_crit = qf(p=.05,df1=df_between,df2=df_within,lower.tail=FALSE) F_crit ``` ``` ## [1] 3.238872 ``` -- - Same result as the table in the back of your textbook, I am just showing a code-based approach to get the critical value here :) `$$F_{obtained} = 4.0650 > F_{critial} = 3.2389$$` -- - Conclusion: we **reject** the null hypothesis and conclude that there **is evidence** that the four groups are not all equal. --- ## Psy202 Week #4 Answer - Compare to build-in R formula .pull-left[ ``` r library(reshape2) a <- data %>% melt(id.vars = "Score") head(a) ``` ``` ## Score variable value ## 1 1 No_Drug 22 ## 2 2 No_Drug 20 ## 3 3 No_Drug 27 ## 4 4 No_Drug 30 ## 5 5 No_Drug 26 ## 6 1 Placebo 25 ``` ] .pull-right[ ``` r a$variable <- factor(a$variable,levels = c("No_Drug","Placebo","Low_Dose","High_Dose")) head(a) ``` ``` ## Score variable value ## 1 1 No_Drug 22 ## 2 2 No_Drug 20 ## 3 3 No_Drug 27 ## 4 4 No_Drug 30 ## 5 5 No_Drug 26 ## 6 1 Placebo 25 ``` ] --- ## Psy202 Week #4 Answer ``` r b <- aov(data = a, value~variable) summary(b) ``` ``` ## Df Sum Sq Mean Sq F value Pr(>F) ## variable 3 250 83.33 4.065 0.0252 * ## Residuals 16 328 20.50 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` - Same F statistics confirms that the by-hand calculations were correct! :) --- ## Psy202 Week #4 Answer - Instructions say to make a figure! (F-U-N FUN!!) .pull-left[ ``` r data %>% melt(id.vars = "Score") %>% group_by(variable) %>% summarise( n=n(), mean=mean(value), sd = sd(value) ) %>% mutate(se = sd / sqrt(n)) %>% ggplot(aes(x=variable,y=mean,colour=variable, fill=variable))+ geom_bar(stat="identity",alpha=0.2)+ geom_errorbar(aes(x=variable,ymin=mean-se,ymax=mean+se),width=0.5)+ theme_classic()+ theme(legend.position = "none")+ theme(plot.title = element_text(hjust = 0.5))+ labs( x="Drug Conditions", y="Time (seconds)", title = "Effect of Drug X on Race Times" )+ ylim(0,35) ``` ] .pull-right[ <img src="data:image/png;base64,#Graph.png" width="1600" /> ] - Data expressed as mean value +/- the standard error of the mean. --- ## Questions? Comments? Concerns?? :)