#Packages

#install.packages("readr")
library("readr")
#install.packages("ggplot2")
library("ggplot2")
#install.packages("viridis")
library("viridis")
## Loading required package: viridisLite
library("tinytex")

#Data

Data <- read.csv("Musicality_Fall_2025.csv")

#Subset Data for groups
Data <- Data[c(16,17,18,19,20,21,25,26,27,28,29,30,40,41,42),]

#Research Questions -Can practice improve rhythm? -Does previous musical experience lead to improved sense of pitch/rhythm? -Is there a relationship between rhythm and pitch?

##Model 1

``` r
#Can practice improve rhythm?
Model1 <- glm(Rhythm ~ Attempt, data = Data)
summary(Model1)
```

```
## 
## Call:
## glm(formula = Rhythm ~ Attempt, data = Data)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  804.667     20.178  39.878 5.57e-15 ***
## Attempt        1.600      9.341   0.171    0.867    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 872.4718)
## 
##     Null deviance: 11368  on 14  degrees of freedom
## Residual deviance: 11342  on 13  degrees of freedom
## AIC: 147.99
## 
## Number of Fisher Scoring iterations: 2
```

##Figure 1

``` r
ggplot(data = Data,
       aes(x = as.factor(Attempt),
           y = Rhythm,
           col = as.factor(Attempt))) +
  geom_jitter() +
  geom_boxplot() +
  geom_smooth(aes(x = Attempt,
                  y = Rhythm,
                  col = Attempt),
              method = lm) +
  ggtitle("Can practice improve rhythm?") +
  ylab("Rhythm Score") +
  xlab("Attempt") +
  guides(color = guide_legend(title = "Attempt")) +
  scale_color_viridis(discrete = TRUE, 
                      option = "viridis") +
  theme_bw()
```

```
## `geom_smooth()` using formula = 'y ~ x'
```

```
## Warning: The following aesthetics were dropped during statistical transformation:
## colour.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
```

<img src="Musicality_files/figure-html/unnamed-chunk-4-1.png" width="672" />

###Homework Questions:
  -What was the hypothesis? Was it supported or rejected?
  The hypothesis is that rhythm is affected by practice. The predictin is that rhythm skill will increase with practice. The hypothesis was rejected based on the data and figure. The prediction for our group's data set was also incorrect.
  -What does the figure show us?
  The figure shows a straight line, which shows no correlation.

##Model 2

#Is there a relationship between rhythm and pitch?
Model2 <- glm(Rhythm ~ Pitch, data = Data)
summary(Model2)
## 
## Call:
## glm(formula = Rhythm ~ Pitch, data = Data)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  1334.00     487.20   2.738   0.0715 .
## Pitch         -21.00      19.64  -1.069   0.3634  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 308.6667)
## 
##     Null deviance: 1278.8  on 4  degrees of freedom
## Residual deviance:  926.0  on 3  degrees of freedom
##   (10 observations deleted due to missingness)
## AIC: 46.297
## 
## Number of Fisher Scoring iterations: 2

##Figure 2

ggplot(data = Data,
       aes(y = Rhythm,
           x = Pitch)) +
  geom_point() +
  geom_smooth(method = lm) +
  ylab("Rhythm Score") +
  xlab("Pitch Score") +
  ggtitle("Is there a relationship between rhythm and pitch?") +
  theme_bw()
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 10 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 10 rows containing missing values or values outside the scale range
## (`geom_point()`).

###Homework Questions: -What was the hypothesis? Was it supported or rejected? The hypothesis is there is relationship between pitch and rhythm. The prediction is that a better sense of pitch correlates to a better sense of rhythm. The hypothesis is rejected due to the p-value. The prediction was also incorrect for our group’s data set. -What does the figure show us? The figure shows a slight negative slope, but not a significant correlation.

##Model 3

``` r
#Does previous musical experience lead to improved sense of rhythm/pitch?
Model3 <- glm(Experience ~ Ratio, family = "binomial", data = Data)
summary(Model3)
```

```
## 
## Call:
## glm(formula = Experience ~ Ratio, family = "binomial", data = Data)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)   71.999     88.043   0.818    0.413
## Ratio         -2.130      2.622  -0.812    0.417
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 5.0040  on 4  degrees of freedom
## Residual deviance: 3.3116  on 3  degrees of freedom
##   (10 observations deleted due to missingness)
## AIC: 7.3116
## 
## Number of Fisher Scoring iterations: 7
```

##Figure 3

``` r
ggplot(data = Data,
       aes(x = Ratio,
           y = Experience)) +
  geom_point() +
  stat_smooth(method = "glm",
              method.args = list(family = "binomial"), 
              se = T) +
  ylab("Musical Experience") +
  xlab("Rhythm/Pitch Score") +
  ggtitle("Does previous musical experience lead to improved sense of rhythm/pitch?") +
  theme_bw()
```

```
## `geom_smooth()` using formula = 'y ~ x'
```

```
## Warning: Removed 10 rows containing non-finite outside the scale range
## (`stat_smooth()`).
```

```
## Warning: Removed 10 rows containing missing values or values outside the scale range
## (`geom_point()`).
```

<img src="Musicality_files/figure-html/unnamed-chunk-8-1.png" width="672" />

###Homework Questions:
  -What was the hypothesis? Was it supported or rejected?
  The hypothesis is that previous musical experience impacts the sense of pitch/rhythm.The prediction is that previous musical experience will improve pitch/rhythm. The hypothesis is rejected due to the p-value. The prediction was also incorrect for our group's data set.
  -What does the figure show us?
  The figure shows a somewhat negative slope, but not a significant correlation.
  -What does a higher or lower rhythm/pitch ratio mean?
  A lower rhythm/pitch ratio means that the participant had bad rhythm and good pitch (aka a lower rhythm score and higher pitch score), and a higher rhythm/pitch ratio means the opposite.