Skip to content

Instantly share code, notes, and snippets.

@stonegold546
stonegold546 / sum_s.R
Last active August 10, 2019 16:34
Sum or factor score
library(lavaan)
library(psych)
sim.fun <- function (lv, lambda, nrep = 2e3) {
np <- nrow(lv)
t(replicate(nrep, {
X <- lv %*% lambda +
matrix(rnorm(np * length(lambda), 0, sqrt(1 - lambda ^ 2)), np, byrow = TRUE)
# summary(cfa(paste("F =~", paste0("V", 1:length(lambda), collapse = " + ")), X, std.lv = TRUE))
@stonegold546
stonegold546 / cfa.R
Last active April 8, 2019 05:14
CFA with Stan
library(lavaan)
library(rstan)
library(rethinking)
library(loo)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
dat <- dplyr::select(HolzingerSwineford1939, x1:x9)
@stonegold546
stonegold546 / icc_fml.R
Last active February 15, 2017 00:07
R code for Full maximum likelihood calculation of ICC
# require(lme4)
mymod <- function(data) {
result <- lme4::lmer(y ~ 1 + (1 | x), data = data, REML = FALSE)
sumy <- summary(result)
varb <- sumy$varcor$x[1]
varw <- sumy$sigma ^ 2
icc <- varb / (varb + varw)
c(icc, varb, varw)
}
# mymod(data)
get_gci_fcn <- function(mymeansqsvec, MC = 100000, B, L, R, alpha = 0.05) {
# Precondition: mymeansqsvec is a vector of mean squares from
# the ANOVA fit of a two-way crossed models. B>2
# is the number of levels of the first factor and
# L>2 is the number of levels of the second factor and
# R>0 is the number of replicates per cell. A two-way
# balanced layout without interaction is assumed.
# MC is the number of Monte Carlo used to construct the
# GCI, with default one-hundred thousand.
@stonegold546
stonegold546 / Web sequence diagram
Created July 23, 2016 15:40
Web sequence diagram for canvas visualisation API
title Using our API: details at /api/v1/routes
note over API: LOGIN
note right of API: GET /api/v1/client_id
Dev->API: Request for Google OAuth Client ID
API->Dev: Returns Google OAuth Client ID as URL Dev can call
Dev->*Google: Request callback code from Google
Google-->Dev: Returns callback code
destroy Google
note right of API: GET /api/v1/use_callback_code

Keybase proof

I hereby claim:

  • I am stonegold546 on github.
  • I am jamesuanhoro (https://keybase.io/jamesuanhoro) on keybase.
  • I have a public key ASDQwPwPar3wn53oAgVAk6oGl6VZsS7Xlucm8AE_Rkgx3wo

To claim this, I am signing this object: