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
############################################################ | |
## Title: Make an Animated Heart in R | |
## Author: Jared Knowles | |
## Date: May 5th, 2012 | |
############################################################ | |
# Make heart curve | |
t<-seq(-100,100,length.out=1000) # Order | |
x<-16*sin(t)^3 # Create the Xs from a formula | |
y<-(13*cos(t))-(5*cos(2*t))-(2*cos(3*t))-(cos(4*t)) # Create Ys from a formula |
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
library(shiny) | |
library(ggplot2) | |
library(eeptools) | |
library(plyr) | |
# Sampling examples | |
probs<-c(.05,.15,.4,.4) | |
samprobs<-c(.4,.4,.15,.05) | |
############### | |
# Convenience functions |
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
# Load ggplot2 | |
library(ggplot2) | |
# Load example data | |
data(mtcars) | |
# Create a character vector of car names | |
mtcars$name <- row.names(mtcars) | |
# Plot car names by mpg | |
ggplot(mtcars, aes(x = name, y = mpg)) + |
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
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 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 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
################################################################################################### | |
## Title: Regression Module Assignment 1 | |
## Exploring Student Composition Effects on Test Score Growth | |
## Author: Jared E. Knowles, Civilytics Consulting | |
## Date: 6/12/2019 | |
## Last Updated: 6/17/2019 | |
################################################################################################### | |
# ---------------------------------------------------------------------------- | |
# Load the data |
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
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 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
# Generate lotto numbers | |
# Avoid a split pot | |
# Author: Jared Knowles | |
# Date: 11/26/2012 | |
# All numbers are equally likely to be selected to win in PowerBall, | |
# but what fun is winning if we have to share the pot? | |
# Therefore, we will only select numbers that minimize our | |
# likelihood of sharing the pot. |
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
################################################################################ | |
# Functions to find the data | |
################################################################################ | |
# Finders | |
# Simple functions that take the ID code from CPE (e.g. 49-00039) and look up | |
# the respective data for it in the structure provided in teh competition | |
find_police_shape <- function(dept_id, kaggle_kernel = FALSE) { | |
if(kaggle_kernel == TRUE) { | |
prefix = "../input/cpe-data/" |
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
############################################################################### | |
## SDP Fall Workshop Predictive Analytics | |
## Advanced / Additional Code Snippets for Working with PA Data and Models | |
## Author: Jared E. Knowles | |
## Date: 09/14/2018 | |
## You do not need to use all or even any of this code. The code does not need to | |
## be run together. This is just a survey of some additional techniques/tricks you | |
## can do in R to make explaining predictive models and complex data easier. | |
## As always - your needs and approaches may different. | |
################################################################################ |
NewerOlder