Skip to content

Instantly share code, notes, and snippets.

---
title: "EID Class - Fall 2021"
author: "Grant Brown"
date: "9/28/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
---
title: "R ABSEIR - R0 and EA-R0 issue"
output: html_document
---
## Issue
Modified code below
```{r Setup, echo=TRUE}
==14436== Memcheck, a memory error detector
==14436== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==14436== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==14436== Command: /usr/lib64/R/bin/R -f class_test.R --restore --save --no-readline
==14436==
==14441== Memcheck, a memory error detector
==14441== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==14441== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==14441== Command: /usr/bin/uname -m
==14441==
library("XBART")
data(iris)
y <- matrix(0, nrow = nrow(iris), ncol = 3)
for (i in 1:nrow(iris)){
y[i, as.numeric(iris$Species)[i]] <- 1
}
sims <- replicate(1000,{
X <- as.data.frame(matrix(rnorm(200*25), ncol = 25, nrow = 200))
colnames(X)[1] <- "Y"
has.cor <- sapply(2:ncol(X), function(i){cor.test(X$Y, X[,i])$p.value < 0.2})
lm.out.1 <- lm(Y~., data = X)
lm.out.2 <- lm(Y~., data = X[,c(1, which(has.cor))])
ftest <- function(lmrslt){
fs <- summary(lmrslt)$fstatistic
library(ABSEIR)
# read in the data set
data(Kikwit1995)
lastTpt <- 80
# Create a model to relate observe data to epidemic process
count <- Kikwit1995$Count
count[(lastTpt+1):length(count)] <- NA
data_model = DataModel(count,
@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 / 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 / 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 / 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)