Skip to content

Instantly share code, notes, and snippets.

@grantbrown
grantbrown / gist:a8cbd3c77a3d6ee9e2c1
Created January 15, 2015 20:22
pa.cv.ncvreg timings
library(ncvreg)
generateData <- function(n,p,nNonzeroBeta, binomial=FALSE){
trueBetaIndex <- (1:p)[order(runif(p,0,1))][1:nNonzeroBeta]
X <- matrix(rnorm(n*p), nrow=n,ncol=p)
trueBeta <- rep(0,p)
trueBeta[trueBetaIndex] <- rnorm(nNonzeroBeta)
if (binomial){
eEta <- exp(X %*% trueBeta)
@grantbrown
grantbrown / gbmtest.Rout
Created February 1, 2015 15:02
Valgrind output for gbm multinomial distribution
==13519== Memcheck, a memory error detector
==13519== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==13519== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==13519== Command: /usr/lib/R/bin/R -f gbmtest.R --restore --save --no-readline
==13519==
==13520== Memcheck, a memory error detector
==13520== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==13520== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==13520== Command: /bin/uname -m
==13520==
@grantbrown
grantbrown / gbmtest.R
Created February 1, 2015 15:03
Quick gbm script
library(gbm)
data(iris)
q = gbm(Species~.,
distribution="multinomial",
data=iris,
interaction.depth=4,
shrinkage = 0.01,
n.minobsinnode=max(30,ceiling(nrow(iris)*0.001)),
n.cores=1,
@grantbrown
grantbrown / gist:e4dc4c2d581574046ddb
Created February 22, 2015 17:14
Data for the 1995 Ebola outbreak in Kikwit
Date,Count
1995-03-06,1
1995-03-07,1
1995-03-08,1
1995-03-09,0
1995-03-10,0
1995-03-11,0
1995-03-12,0
1995-03-13,2
1995-03-14,0
@grantbrown
grantbrown / NormalDemonstration.R
Last active December 18, 2015 02:09
Plots a normal curve and shaded region.
plotNormal = function(lb, ub, mu = 0, sigma = 1)
{
# Generate X an Y pairs for normal curve
X = seq(mu - 4*sigma, mu + 4*sigma, 0.1)
Y = dnorm(X, mean = mu, sd = sigma)
# Plot the normal curve line, lablel axes and plot
plot(X,Y, type = "l", main = "Normal PDF", xlab = "x", ylab = "Density(x)")
# Calculate visible bounds (no use plotting tails that are off the screen)
lb2 = min(max(lb, mu-4*sigma), min(ub, mu+4*sigma))
ub2 = max(max(lb, mu-4*sigma), min(ub, mu+4*sigma))
@grantbrown
grantbrown / BMI.txt
Created June 4, 2013 20:10
BMI vs. % Calories from Fat Data Set
BMI FatPct
27.2 34.6
23.7 39.5
24.9 41.3
32.2 33.3
36.8 43
20 32.3
29.5 31.5
29.3 36.5
44.6 41.3
@grantbrown
grantbrown / tDistributionExample.R
Created June 4, 2013 22:08
Animated illustration of how degrees of freedom affect the shape of the student's-t distribution.
# T Distribution Illustration
TimeDelay = 0.5
plotT = function(df, add = FALSE)
{
f = function(x)
{
return(dt(x, df))
}
curve(f, xlim = c(-6,6), ylim = c(0, 0.5), add = add, main = "T Distribution vs. Standard Normal",ylab = "Density")
@grantbrown
grantbrown / HeartDiseaseDiabetes.csv
Created June 16, 2013 02:14
Heart Disease and Diabetes CSV File
county HeartCrude HeartAgeAdj DiabetesCrude DiabetesAgeAdj
adair 441.6 211.3 28.7 14.6
adams 352.9 174.4 29 24.5
audubon 318.9 149.9 32.2 17
clarke 389.2 261.6 39.6 31
davis 252.7 172.7 53.8 36.8
decatur 301.2 202.1 28.7 19.2
fremont 289.1 169.1 42.4 25.2
greene 351.2 177 18.7 11.4
howard 379.4 197 25.2 14.9
@grantbrown
grantbrown / Homework3Template.R
Created June 16, 2013 02:48
R code template for working on homework 3
# Homework 3 R code template
# Before doing anything else, get a copy of HeartDiseaseDiabetes.csv
# This file is available on the github site, and an excel version is
# available on icon. Remember that to use the excel version, you need
# to open it in excel or libre office and save a copy as a csv.
# Once you have obtained a copy of the data set in csv format, take
# note of where you've saved it. We need to tell R to use that folder
@grantbrown
grantbrown / ConfidenceBandExample.R
Created June 16, 2013 02:47
Example code and comments for creating a confidence interval at a particular X0 for the mean of Y in a simple linear regression problem.
# To illustrate the use of confidence bands, let's just make up
# a data example. First, to ensure that everyone's simulated data
# looks the same in case you want to work together, let's tell R
# to use the same starting point for random number generation.
# (don't worry about how this works)
set.seed(12345)