This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## fancyaxis: Draw axis which shows minimum, maximum, quartiles | |
## and mean | |
## | |
## Copyright (C) 2005 Steven J. Murdoch <http://www.cl.cam.ac.uk/users/sjm217/> | |
## | |
## This program is free software; you can redistribute it and/or modify | |
## it under the terms of the GNU General Public License as published by | |
## the Free Software Foundation; either version 2 of the License, or | |
## (at your option) any later version. | |
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# credit: https://raw.githubusercontent.com/bearloga/Quartile-frame-Scatterplot/master/qfplot.R | |
library(ggplot2) # by Hadley Wickham | |
library(grid) # Required for the special axes. | |
qfplot <- function(x,y,...) { | |
# We use margins for a cleaner graph. | |
# They are calculated as 5% of the range. | |
# Feel free to play around with these (10% works well too). | |
y.margin <- 0.05 * (max(y)-min(y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#addmargins(table) # for freq table reference and input | |
bayes.fisher <- function(y1, n1, y2, n2) { | |
# SIMULATION | |
I = 10000 # simulations | |
theta1 = rbeta(I, y1+1, (n1-y1)+1) | |
theta2 = rbeta(I, y2+1, (n2-y2)+1) | |
diff = theta1-theta2 # simulated diffs | |
# OUTPUT | |
quantiles = quantile(diff,c(0.005,0.025,0.5,0.975,0.995)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rise$PEduc <- factor(rise$PEduc, levels = c(1:7), labels = c("No Formal Schooling", "Some Elementary School", | |
"Completed Elementary School", "Some Middle and High School", "Competed High School Diploma or GED", | |
"Some College", "Completed 4-Year Degree or Higher")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----------------Structural Model--------------# | |
# Monte Carlo (MC) Study with a Simple CFA w/no missing data | |
# The idea with this MC study is to specify a theoretical model, | |
# by this I mean you input the hypothesized parameter estimates | |
# or estimates from a model you have already run. | |
# The Monte Carlo aspect means to examine the variability | |
# in the parameter estimates and fit statistics. | |
# MC studies are an important element to establish | |
# power in a study. | |
#-----MC Study of Uncertainty in Parameter Estimates-----# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Fun stuff with plyr | |
#------------------- | |
#plyr .data, .variables to split on and .fun function applied | |
#understand the naming conventions of plyr with the first 2 letters | |
#e.g., ddply dd= split dataframe apply function out dataframe | |
#e.g., dlply dl = split dataframe apply function out list | |
#d = dataframe | |
#l = list | |
#a = array | |
#------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get variable names for mtcars dataset in rbase | |
colnames(mtcars) | |
#if yow want to recode variables the lazy way | |
fix(mtcars) #downside is that it isn't hard coded, and therefore not reproducible | |
#use the reshape package | |
library(reshape) | |
test <- rename(mtcars, c(disp="renamedisp")) #reproducible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create artifical data to emulate SEM model fit statistics | |
chiSq <- 1600 | |
df <- 780 | |
p <- 0.95 | |
CFI <- 0.95 | |
TLI <- 0.95 | |
RMSEA <- 0.04 | |
LOWRMSEA <- 0.03 | |
HIGHRMSEA <- 0.04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |