R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

#Began by setting working directory, creating a chunk, and reading in data. 



read.csv("Final Project Data.csv")
##        ID Lhippvol Sex Assocmem     Fvol     Mvol
## 1  BAD001 3279.872   F     0.05 3279.872 2943.488
## 2  BAD002 2975.744   F     0.50 2975.744 3613.184
## 3  BAD004 3431.936   F     0.15 3431.936 3982.336
## 4  BAD005 3565.568   F     0.45 3565.568 3777.024
## 5  BAD102 4009.984   F     0.70 4009.984 3778.560
## 6  BAD104 4381.696   F     0.50 4381.696 3542.016
## 7  BAD106 3531.264   F     0.75 3531.264 4477.952
## 8  BAD108 4470.272   F     0.10 4470.272 4609.024
## 9  BAD109 4089.856   F     0.90 4089.856 3832.320
## 10 BAD110 3814.912   F     0.85 3814.912 3964.416
## 11 BAD116 3876.864   F     0.55 3876.864 3876.864
## 12 BAD117 3832.320   M     0.70       NA       NA
## 13 BAD121 3964.416   M     0.80       NA       NA
## 14 BAD122 3876.864   M     0.75       NA       NA
## 15 BAD003 2943.488   M     0.00       NA       NA
## 16 BAD107 3613.184   M     0.65       NA       NA
## 17 BAD111 3982.336   M     0.20       NA       NA
## 18 BAD112 3777.024   M     0.80       NA       NA
## 19 BAD115 3778.560   M     0.15       NA       NA
## 20 BAD118 3542.016   M     0.20       NA       NA
## 21 BAD120 4477.952   M     0.30       NA       NA
## 22 BAD123 4609.024   M     0.65       NA       NA
#Loaded libraries  

library("stats") 
library("naniar") 
library("dplyr") 
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("psych") 
library("ggplot2") 
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
library("ggeffects") 
library("tidyr") 
library("Rmisc") 
## Loading required package: lattice
## Loading required package: plyr
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
library("lsr") 
library("easystats")
## # Attaching packages: easystats 0.5.2 (red = needs update)
## ✖ insight     0.18.6   ✖ datawizard  0.6.3 
## ✔ bayestestR  0.13.0   ✖ performance 0.10.0
## ✖ parameters  0.19.0   ✔ effectsize  0.8.2 
## ✔ modelbased  0.8.5    ✔ correlation 0.8.3 
## ✖ see         0.7.3    ✔ report      0.5.5 
## 
## Restart the R-Session and update packages in red with `easystats::easystats_update()`.
#Viewed data to ensure it was correct and renamed it

data<- read.csv("Final Project Data.csv") 

View(data) 
#Checking for missing data 

vis_miss(data)
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## Please use `gather()` instead.

#Calculating some descriptive stats just to see them

#Finding the volume mean
mean(data$Lhippvol)  
## [1] 3810.234
#Finding the volume median
median(data$Lhippvol)    
## [1] 3823.616
#Finding range  
range(data$Lhippvol) 
## [1] 2943.488 4609.024
#Finding standard deviation
sd(data$Lhippvol) 
## [1] 444.521
#Running an independent t-test to assess male hippocampal volume vs female vol 

sexcomparison<-t.test(data$Mvol,data$Fvol ,var.equal=T) 

report(sexcomparison) 
## Warning: Missing values detected. NAs dropped.
## Effect sizes were labelled following Cohen's (1988) recommendations.
## 
## The Two Sample t-test testing the difference between data$Mvol and data$Fvol
## (mean of x = 3854.29, mean of y = 3766.18) suggests that the effect is
## positive, statistically not significant, and very small (difference = 88.11,
## 95% CI [-314.95, 491.17], t(20) = 0.46, p = 0.653; Cohen's d = 0.19, 95% CI
## [-0.65, 1.03])
#Running cohens d to check effect size

Mvol <-c(data$Mvol) 
Fvol <-c(data$Fvol) 

cohensD(Mvol,Fvol) 
## [1] 0.1944409
#Running SD

sd(data$Mvol, na.rm=T) 
## [1] 445.5341
sd(data$Fvol, na.rm=T)
## [1] 460.6377
#Graphing the t-test   

read.csv("FD_Graph.csv")
##      Volume Sex
## 1  3279.872   F
## 2  2975.744   F
## 3  3431.936   F
## 4  3565.568   F
## 5  4009.984   F
## 6  4381.696   F
## 7  3531.264   F
## 8  4470.272   F
## 9  4089.856   F
## 10 3814.912   F
## 11 3876.864   F
## 12 2943.488   M
## 13 3613.184   M
## 14 3982.336   M
## 15 3777.024   M
## 16 3778.560   M
## 17 3542.016   M
## 18 4477.952   M
## 19 4609.024   M
## 20 3832.320   M
## 21 3964.416   M
data2<- read.csv("FD_Graph.csv") 

ggplot(data2, aes(fill=Sex, y=Volume, x=Sex)) + 
    geom_bar(position="dodge", stat="identity")+
  xlab("Sex")+
  ylab("Left Hippocampal Volume") 

#Adding in standard error 

dfSumm <- data2 %>%
  group_by(Sex) %>%
  dplyr::summarise(
    n=n(), #Tells it what n is for SE calculation later
    sd = sd(Volume, na.rm=T), #Finds SD for SE calculation
    Volume = mean(Volume,na.rm=T) #Mean for later
    )%>%
  mutate( se=sd/sqrt(n))  %>% #Calculates SE
  mutate( ci=se) #Calculates confidence interval. 

ggplot(dfSumm, aes(Sex, Volume)) +
  geom_col(fill=c("pink", "blue")) +
  geom_errorbar(aes(ymin = Volume-ci, ymax = Volume+ci),width=0.3)+
  xlab("Sex")+
  ylab("Left Hippocampal Volume")

#Running a correlation between Volume and Associative Memory Scores 

r <- corr.test(data$Lhippvol,data$Assocmem)
print(r,short=F)    
## Call:corr.test(x = data$Lhippvol, y = data$Assocmem)
## Correlation matrix 
## [1] 0.25
## Sample Size 
## [1] 22
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
## [1] 0.25
## 
##  Confidence intervals based upon normal theory.  To get bootstrapped values, try cor.ci
##       raw.lower raw.r raw.upper raw.p lower.adj upper.adj
## NA-NA     -0.19  0.25      0.61  0.25     -0.19      0.61
#Saving function as an object and running a regression  

reg <- lm(Assocmem~Lhippvol, data=data)
summary(reg) 
## 
## Call:
## lm(formula = Assocmem ~ Lhippvol, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4967 -0.2918  0.0413  0.2419  0.3669 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.1505959  0.5448012  -0.276    0.785
## Lhippvol     0.0001672  0.0001421   1.177    0.253
## 
## Residual standard error: 0.2894 on 20 degrees of freedom
## Multiple R-squared:  0.06475,    Adjusted R-squared:  0.01799 
## F-statistic: 1.385 on 1 and 20 DF,  p-value: 0.2531
report(reg)
## We fitted a linear model (estimated using OLS) to predict Assocmem with
## Lhippvol (formula: Assocmem ~ Lhippvol). The model explains a statistically not
## significant and weak proportion of variance (R2 = 0.06, F(1, 20) = 1.38, p =
## 0.253, adj. R2 = 0.02). The model's intercept, corresponding to Lhippvol = 0,
## is at -0.15 (95% CI [-1.29, 0.99], t(20) = -0.28, p = 0.785). Within this
## model:
## 
##   - The effect of Lhippvol is statistically non-significant and positive (beta =
## 1.67e-04, 95% CI [-1.29e-04, 4.64e-04], t(20) = 1.18, p = 0.253; Std. beta =
## 0.25, 95% CI [-0.20, 0.71])
## 
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.
#Mean centering data because this data doesn't have a meaningful zero

data$Lhippvol <- scale(data$Lhippvol,center=T,scale=F)
#Running the updated regression

reg2 <- lm(Assocmem~Lhippvol,data=data)
summary(reg2) 
## 
## Call:
## lm(formula = Assocmem ~ Lhippvol, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4967 -0.2918  0.0413  0.2419  0.3669 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.4863636  0.0616984   7.883 1.46e-07 ***
## Lhippvol    0.0001672  0.0001421   1.177    0.253    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2894 on 20 degrees of freedom
## Multiple R-squared:  0.06475,    Adjusted R-squared:  0.01799 
## F-statistic: 1.385 on 1 and 20 DF,  p-value: 0.2531
report(reg2)
## We fitted a linear model (estimated using OLS) to predict Assocmem with
## Lhippvol (formula: Assocmem ~ Lhippvol). The model explains a statistically not
## significant and weak proportion of variance (R2 = 0.06, F(1, 20) = 1.38, p =
## 0.253, adj. R2 = 0.02). The model's intercept, corresponding to Lhippvol = 0,
## is at 0.49 (95% CI [0.36, 0.62], t(20) = 7.88, p < .001). Within this model:
## 
##   - The effect of Lhippvol is statistically non-significant and positive (beta =
## 1.67e-04, 95% CI [-1.29e-04, 4.64e-04], t(20) = 1.18, p = 0.253; Std. beta =
## 0.25, 95% CI [-0.20, 0.71])
## 
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.
#Plotting the regression 

g <- ggpredict(reg,terms=c("Lhippvol"))

plot(g)+labs(x="Left Hippocampal Volume", y="Associative Memory",title="Associative Memory Scores and Left Hippocampal Volume")

#Getting package citations  

citation("stats") 
## 
## The 'stats' package is part of R.  To cite R in publications use:
## 
##   R Core Team (2022). R: A language and environment for statistical
##   computing. R Foundation for Statistical Computing, Vienna, Austria.
##   URL https://www.R-project.org/.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {R: A Language and Environment for Statistical Computing},
##     author = {{R Core Team}},
##     organization = {R Foundation for Statistical Computing},
##     address = {Vienna, Austria},
##     year = {2022},
##     url = {https://www.R-project.org/},
##   }
## 
## We have invested a lot of time and effort in creating R, please cite it
## when using it for data analysis. See also 'citation("pkgname")' for
## citing R packages.
citation("naniar") 
## 
## To cite package 'naniar' in publications use:
## 
##   Tierney N, Cook D, McBain M, Fay C (2021). _naniar: Data Structures,
##   Summaries, and Visualisations for Missing Data_. R package version
##   0.6.1, <https://CRAN.R-project.org/package=naniar>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {naniar: Data Structures, Summaries, and Visualisations for Missing Data},
##     author = {Nicholas Tierney and Di Cook and Miles McBain and Colin Fay},
##     year = {2021},
##     note = {R package version 0.6.1},
##     url = {https://CRAN.R-project.org/package=naniar},
##   }
citation("dplyr") 
## 
## To cite package 'dplyr' in publications use:
## 
##   Wickham H, François R, Henry L, Müller K (2022). _dplyr: A Grammar of
##   Data Manipulation_. R package version 1.0.10,
##   <https://CRAN.R-project.org/package=dplyr>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {dplyr: A Grammar of Data Manipulation},
##     author = {Hadley Wickham and Romain François and Lionel Henry and Kirill Müller},
##     year = {2022},
##     note = {R package version 1.0.10},
##     url = {https://CRAN.R-project.org/package=dplyr},
##   }
citation("psych") 
## 
## To cite the psych package in publications use:
## 
##   Revelle, W. (2022) psych: Procedures for Personality and
##   Psychological Research, Northwestern University, Evanston, Illinois,
##   USA, https://CRAN.R-project.org/package=psych Version = 2.2.9.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {psych: Procedures for Psychological, Psychometric, and Personality Research},
##     author = {William Revelle},
##     organization = { Northwestern University},
##     address = { Evanston, Illinois},
##     year = {2022},
##     note = {R package version 2.2.9},
##     url = {https://CRAN.R-project.org/package=psych},
##   }
citation("ggplot2") 
## 
## To cite ggplot2 in publications, please use:
## 
##   H. Wickham. ggplot2: Elegant Graphics for Data Analysis.
##   Springer-Verlag New York, 2016.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Book{,
##     author = {Hadley Wickham},
##     title = {ggplot2: Elegant Graphics for Data Analysis},
##     publisher = {Springer-Verlag New York},
##     year = {2016},
##     isbn = {978-3-319-24277-4},
##     url = {https://ggplot2.tidyverse.org},
##   }
citation("ggeffects") 
## 
## To cite package 'ggeffects' in publications use:
## 
##   Lüdecke D (2018). "ggeffects: Tidy Data Frames of Marginal Effects
##   from Regression Models." _Journal of Open Source Software_, *3*(26),
##   772. doi:10.21105/joss.00772 <https://doi.org/10.21105/joss.00772>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {ggeffects: Tidy Data Frames of Marginal Effects from Regression Models.},
##     volume = {3},
##     doi = {10.21105/joss.00772},
##     number = {26},
##     journal = {Journal of Open Source Software},
##     author = {Daniel Lüdecke},
##     year = {2018},
##     pages = {772},
##   }
citation("tidyr") 
## 
## To cite package 'tidyr' in publications use:
## 
##   Wickham H, Girlich M (2022). _tidyr: Tidy Messy Data_. R package
##   version 1.2.1, <https://CRAN.R-project.org/package=tidyr>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {tidyr: Tidy Messy Data},
##     author = {Hadley Wickham and Maximilian Girlich},
##     year = {2022},
##     note = {R package version 1.2.1},
##     url = {https://CRAN.R-project.org/package=tidyr},
##   }
citation("Rmisc") 
## 
## To cite package 'Rmisc' in publications use:
## 
##   Hope RM (2022). _Rmisc: Ryan Miscellaneous_. R package version 1.5.1,
##   <https://CRAN.R-project.org/package=Rmisc>.
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {Rmisc: Ryan Miscellaneous},
##     author = {Ryan M. Hope},
##     year = {2022},
##     note = {R package version 1.5.1},
##     url = {https://CRAN.R-project.org/package=Rmisc},
##   }
## 
## ATTENTION: This citation information has been auto-generated from the
## package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.
citation("lsr") 
## 
## To cite the lsr package in publications use:
## 
##   Navarro, D. J. (2015) Learning statistics with R: A tutorial for
##   psychology students and other beginners. (Version 0.6) University of
##   New South Wales. Sydney, Australia
## 
## A BibTeX entry for LaTeX users is
## 
##   @Manual{,
##     title = {Learning statistics with R: A tutorial for psychology students and other beginners. (Version 0.6)},
##     author = {Danielle Navarro},
##     organization = {University of New South Wales},
##     address = {Sydney, Australia},
##     year = {2015},
##     note = {R package version 0.5.1},
##     url = {https://learningstatisticswithr.com},
##   }
citation("easystats")
## 
## To cite datawizard in publications use:
## 
##   Lüdecke, Patil, Ben-Shachar, Wiernik, & Makowski (2022). easystats:
##   Framework for Easy Statistical Modeling, Visualization, and
##   Reporting. CRAN. Available from
##   https://easystats.github.io/easystats/
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {easystats: Framework for Easy Statistical Modeling, Visualization, and Reporting},
##     author = {Daniel Lüdecke and Mattan S. Ben-Shachar and Indrajeet Patil and Brenton M. Wiernik and Dominique Makowski},
##     journal = {CRAN},
##     year = {2022},
##     note = {R package},
##     url = {https://easystats.github.io/easystats/},
##   }