-1

I have a dataset of the following form.

Rows: 110
Columns: 11
$ ID                    <int> 1, 2, 3, 4, 5, 6, 7, 8, 9,…
$ happy_experimental    <dbl> 546.32, 549.03, 596.21, 46…
$ happy_control         <dbl> 504.87, 314.97, 539.73, 43…
$ confused_experimental <dbl> 507.56, 446.49, 531.34, 26…
$ confused_control      <dbl> 518.58, 513.33, 362.34, 65…
$ group                 <chr> "experimental", "control",…
$ charisma_time1        <int> 52, 56, 71, 44, 43, 56, 43…
$ charisma_time2        <int> 52, 58, 66, 41, 46, 64, 50…
$ sentimentality        <int> 23, 22, 23, 13, 21, 18, 25…
$ decisiveness          <int> 35, 22, 20, 10, 15, 15, 14…
$ sociability           <int> 42, 46, 36, 15, 36, 21, 45…

I need to test the hypothesis that, Participants in the experimental group will be higher on charisma at Time 2 compared to Time 1, but there is no difference for participants in the control group.

The problem is both charisma_Time1 and charisma_Time2 are numeric variables and the group is the factor. How can I run ANOVA with these variables? I ran some ANOVA but I am not sure if the method is okay or not. Can anyone please suggest what should be the formula for testing the hypothesis with an ANOVA?

Aashiq Reza
  • 153
  • 2
  • 13
  • 1
    If you need help choosing how to set up a statistical model, you should ask for help at [stats.se] instead. You are likely to get better help there. This is not really a specific programming question that's appropriate for Stack Overflow. Questions here should have code included and data in a reproducible format, [not an image](https://meta.stackoverflow.com/q/285551/2372064) – MrFlick Dec 05 '22 at 20:51
  • I need the R code to solve this ANOVA problem. I am looking for suggestions on how I can implement this on R. – Aashiq Reza Dec 05 '22 at 20:57

1 Answers1

0

Suppose this is your dataset:

set.seed(123)
data <- data.frame(
  charisma_time1 = sample(10,10,T),
  charisma_time2 = sample(10,10,T),
  group = c("experimental", "control"))

str(data)
#> 'data.frame':    10 obs. of  3 variables:
#>  $ charisma_time1: int  3 3 10 2 6 5 4 6 9 10
#>  $ charisma_time2: int  5 3 9 9 9 3 8 10 7 10
#>  $ group         : chr  "experimental" "control" "experimental" "control" ...

As you must test against both "group" and "charisma" you first need to reshape your data. This is done with reshape in base R (dplyr::pivot_longer is easier however)

data2 <- reshape(data, direction="long", 
         varying = c("charisma_time1", "charisma_time2"),
         sep = "_", )
data2

#>                 group  time charisma id
#> 1.time1  experimental time1        3  1
#> 2.time1       control time1        3  2
#> 3.time1  experimental time1       10  3
#> 4.time1       control time1        2  4
#> 5.time1  experimental time1        6  5
#> 6.time1       control time1        5  6
#> 7.time1  experimental time1        4  7
# ...

In this format you can do anova on group and on time1 (or multiple-way on both, like charisma ~ group + data2

# convert string to factor
data2 <- data.frame(data2, stringsAsFactors = T)

anova(aov(charisma ~ group, data2))
#> Analysis of Variance Table
#> 
#> Response: charisma
#>           Df Sum Sq Mean Sq F value Pr(>F)
#> group      1   4.05  4.0500  0.4768 0.4987
#> Residuals 18 152.90  8.4944
anova(aov(charisma ~ time, data2))
#> Analysis of Variance Table
#> 
#> Response: charisma
#>           Df Sum Sq Mean Sq F value Pr(>F)
#> time       1  11.25 11.2500  1.3898 0.2538
#> Residuals 18 145.70  8.0944

You can also filter the data if you want to test data2 between times but only in the experimental group

anova(aov(charisma ~ time, data2[data2$group == "experimental",]))

# Response: charisma
#           Df Sum Sq Mean Sq F value Pr(>F)  
# time       1   22.5    22.5  3.8793 0.0844 .
# Residuals  8   46.4     5.8                 
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Hope this could help you.

Ric
  • 5,362
  • 1
  • 10
  • 23