Skip to content

Instantly share code, notes, and snippets.

>qol.scores <- c(45, 80, 70, 70) # QoL data
>single.case(qol.scores, baseline = 1, level = .05) # Time.1 is baseline
Single-case data analysis
x dx z dz Sig
Time.1 45 Baseline -1.42 Baseline Baseline
Time.2 80 -35 0.92 -2.34 *
Time.3 70 -25 0.25 -1.67 *
Time.4 70 -25 0.25 -1.67 *
require(boot)
require(car)
require(MASS)
require(QuantPsyc) # lm.beta() function
#---- Bootstrap Mediation Function ----
boot.med <- function(data, formula.m, formula.y, iv, mv, i) {
data.resamp <- data[i,]
reg.m <- lm(formula.m, data=data.resamp)
>med(data=rfe, iv = "SOQsos", dv = "MBASo", mv="REIappear", cv="AGE", reps=1000)
Independent Variable: SOQsos
Dependent Variable: MBASo
Mediator Variable: REIappear
IV (and CVs) on DV
Estimate SE Pr(>|z|) LL UL Beta
(Intercept) 3.69132749 0.199476668 3.154675e-40 3.300353220 4.082301760 NA
SOQsos 0.01914967 0.005112734 2.578910e-04 0.009128709 0.029170628 0.2940897
**********************************************************************
* Project: Classification of Eating Disorders using EDE-Q
* Coded by: Sam Mancuso
* Version: 1.0
* Date: 22 July 2014
***********************************************************************
** NB
* bmi_at_assessment = Clinician assessed BMI
* menstrual_status_on_admission = Clinician assessed menstrual status
# =================================================================
#
# Analysis of repeated single-case data
#
# Mueser, K. T., Yarnold, P. R., & Foy, D. W. (1991).
# Statistical Analysis for Single-Case Designs Evaluating Outcome
# of Imaginal Exposure Treatment of Chronic PTSD.
# Behavior Modification, 15(2), 134-155.
#
# Coded by: Sam Mancuso
@smancuso
smancuso / ExpSample.R
Last active June 7, 2018 18:08
Sample Size Estimation for Comparisons between Two Groups
# -------------------------------------------------------------------------
# Sample Size Estimation for Comparisons between Two Groups
# in Experimental Designs
# Coded by: Sam Mancuso
# Date: 03 March 2015
# Version: 2.0
# Revision Date: 05 March 2015
# Blog: sammancuso.wordpress.com
# -------------------------------------------------------------------------
@smancuso
smancuso / Model1_Ex10.2_Data.R
Last active June 8, 2018 09:41
Example 10.2 RePROCESS Model 1 Data Import
# Import 'protest' data and convert 'protest' to 'labelled'
protest <- read.csv("protest.csv", header = TRUE) %>%
mutate(
protest = labelled(
protest,
c(
"No protest" = 0,
"Individual protest" = 1,
"Collective protest" = 2
)
@smancuso
smancuso / Power.R
Created November 5, 2018 00:15
Shiny App code for linear mixed model sample size calculations
# Load the shiny and longpower packages
library(shiny)
library(longpower)
# UI ----------------------------------------------------------------------
ui <- fluidPage(
# Add title
titlePanel("Linear Mixed Model Sample Size Calculations"),
SDadjP.lm <- function(model, B = 10000, seed = 1, rob = FALSE) {
# Stop if model not 'lm' object
stopifnot(class(model)[1] == "lm")
# Set seed for reproducibility
set.seed(seed)
# Set robust estimator
est <- ifelse(rob == TRUE, "HC3", "const")
# Set covariance matrix
covMat <- vcovHC(model, est)
# Get observed t-values
# Meta-Analysis Function --------------------------------------------------
## Summary Effect Size and its Standard Error using DL method (Eqs. 1-3)
mw_est <- function(yi,
vi,
data,
lab,
method = c("DL", "DL2"),
ci = .95,
Q.profile = FALSE,
pi = FALSE,