This file contains hidden or 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
# Script to demonstrate distributions | |
library(VGAM) | |
library(eeptools) | |
library(shiny) | |
library(ggplot2) | |
shinyServer(function(input,output){ |
This file contains hidden or 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
# Script to demonstrate distributions | |
library(eeptools) | |
library(shiny) | |
library(ggplot2) | |
rnormcor <- function(x,rho) rnorm(1,rho*x,sqrt(1-rho^2)) | |
shinyServer(function(input,output){ | |
output$distPlot<-reactivePlot(function(){ |
This file contains hidden or 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
library(shiny) | |
library(scales) | |
shinyServer(function(input,output){ | |
trialInput<-reactive(function(){ | |
bias<-input$coin | |
sims<-input$obs | |
reps<-input$reps | |
trials<-rbinom(reps,sims,0.5+bias) | |
}) |
This file contains hidden or 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
library(shiny) | |
# data from : http://is-r.tumblr.com/post/35266021903/five-thirty-hate | |
election.data <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/election2012.csv") | |
#election.data <- read.csv("electiondata.csv") | |
shinyServer(function(input,output){ | |
output$voteplot<-reactivePlot(function(){ | |
Mode <- function(X) { |
This file contains hidden or 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
library(lavaan) | |
model <- ' | |
# latent variable definitions | |
ind60 =~ x1 + x2 + x3 | |
dem60 =~ y1 + a*y2 + b*y3 + c*y4 | |
dem65 =~ y5 + a*y6 + b*y7 + c*y8 | |
# regressions | |
dem60 ~ ind60 | |
dem65 ~ ind60 + dem60 |
This file contains hidden or 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
How to Ask for Help using R | |
======================================================== | |
The key to getting good help with an R problem is to provide a minimally working | |
reproducible example (MWRE). Making an MWRE is really easy with R, and it will | |
help ensure that those helping you can identify the source of the error, and | |
ideally submit to you back the corrected code to fix the error instead of sending | |
you hunting for code that works. To have an MWRE you need the following items: | |
- a minimal dataset that produces the error |
This file contains hidden or 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
# Helper functions that allow string arguments for dplyr's data modification functions like arrange, select etc. | |
# Author: Sebastian Kranz | |
# Examples are below | |
#' Modified version of dplyr's filter that uses string arguments | |
#' @export | |
s_filter = function(.data, ...) { | |
eval.string.dplyr(.data,"filter", ...) | |
} |
This file contains hidden or 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 |
This file contains hidden or 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
# Calculate the AUC of a GLM model easily | |
# Jared Knowles | |
# model = a fitted glm in R | |
# newdata = an optional data.frame of new fitted values | |
auc.glm <- function(model, newdata = NULL){ | |
if(missing(newdata)){ | |
resp <- model$y | |
# if(class(resp) == "numeric"){ | |
# resp <- factor(resp) | |
# } |
This file contains hidden or 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
predict.robust <- function(model, data, robust_vcov = NULL, level = 0.95, | |
interval = "prediction"){ | |
# adapted from | |
# https://stackoverflow.com/questions/38109501/how-does-predict-lm-compute-confidence-interval-and-prediction-interval | |
# model is an lm object from r | |
# data is the dataset to predict from | |
# robust_vcov must be a robust vcov matrix created by V <- sandwich::vcovHC(model, ...) | |
# level = the % of the confidence interval, default is 95% | |
# interval = either "prediction" or "confidence" - prediction includes uncertainty about the model itself | |
if(is.null(robust_vcov)){ |