Skip to content

Instantly share code, notes, and snippets.

View dsquintana's full-sized avatar

Dan Quintana dsquintana

View GitHub Profile
@dsquintana
dsquintana / contour-enhanced-funnel-plot
Last active August 10, 2018 03:12
An R script to generate various contour-enhanced funnel plots
### Contour-enhanced funnel plots using metafor ###
# Load metafor package
library("metafor")
# Load dataset
dat <- get(data(dat.molloy2014))
@dsquintana
dsquintana / Power
Created July 20, 2018 18:40
Power analysis
# Load package
library(pwr)
# Perform power analysis
pwr.t2n.test(sig.level = 0.05, n1= 32,n2= 23, power = 0.8,
alternative="two.sided")
@dsquintana
dsquintana / Equivalence test
Created July 20, 2018 19:05
Equivalence test
# Load TOSTER package
library(TOSTER)
# Perform equivalence test
TOSTtwo(m1=37.33,m2=39.65 ,sd1=13.40,sd2=15.91,n1=23,n2=32,
low_eqbound_d=-0.26,high_eqbound_d=0.26,
plot = TRUE)
@dsquintana
dsquintana / t-statistic
Created July 20, 2018 19:30
t-statistic
# Write function
t.test2 <- function(m1,m2,s1,s2,n1,n2,m0=0,equal.variance=FALSE)
{
if( equal.variance==FALSE )
{
se <- sqrt( (s1^2/n1) + (s2^2/n2) )
# welch-satterthwaite df
df <- ( (s1^2/n1 + s2^2/n2)^2 )/( (s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1) )
} else
@dsquintana
dsquintana / trends
Created July 23, 2019 19:09
A script for visualising research trends
@dsquintana
dsquintana / packages_data
Created July 24, 2019 11:40
Load up packages
library(synthpop)
library(tidyverse)
library(cowplot)
h_dat <- read_csv("help.csv")
> summary(aov(happy_o ~drugcond*emocond,data=h_dat)) # Interaction effect on happiness
Df Sum Sq Mean Sq F value Pr(>F)
drugcond 1 1.70 1.70 1.436 0.2352
emocond 1 34.21 34.21 28.950 1.16e-06 ***
drugcond:emocond 1 4.40 4.40 3.726 0.0581 .
Residuals 63 74.44 1.18
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
49 observations deleted due to missingness
> m1 = lm(happy_o ~ 1 + drugcond + emocond,
data = h_dat) # Model 1 with main effects only
> m2 = lm(happy_o ~ 1 + drugcond + emocond +
drugcond:emocond, data = h_dat) # Model with main effects and interaction
> summary(m2) # Summary of model 2 (with same p-value as original ANOVA for the interaction)
Call:
lm(formula = happy_o ~ 1 + drugcond + emocond + drugcond:emocond,
h_dat_s <- syn(h_dat, m = 1, seed = 1969)
compare(h_dat_s, h_dat,
stat = "counts", # Selecting counts instead of percentage
cols = c("#62B6CB", "#1B4965")) # Changing colours
> help_glm_h <- lm(happy_o ~ 1 + drugcond +
emocond + drugcond:emocond,
data = h_dat) # Model from observed data
> help_syn_glm_h <- lm.synds(happy_o ~ 1 + drugcond +
emocond + drugcond:emocond,
data = h_dat_s) # Model from synthesized data
> compare(help_syn_glm_h, h_dat) # A comparison of the models