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(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) |
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
==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== |
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(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, |
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
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 |
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
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)) |
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
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 |
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
# 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") |
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
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 |
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
# 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 |
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
# 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) |
OlderNewer