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
#fit a Cox proportional hazards model and plot the | |
#predicted survival | |
fit <- coxph(Surv(futime, fustat) ~ treat + julian + julian2, data = mydata) | |
plot(survfit(fit, newdata=data.frame(treat="control",julian=200,julian2=4000)), | |
xscale=1, xlab = "Days", ylab="Survival",conf.int=F,col="blue") | |
#also plot the predicted survival for treatment | |
lines(survfit(fit, newdata=data.frame(treat="treatment",julian=200,julian2=4000)), | |
xscale=1, xlab = "Days", ylab="Survival",col="red") |
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 many simulations? | |
niter=100000 | |
#Create matrix to hold final drawings (final) | |
#and vector to hold whether or not person "A" (Jeremy) won in a particular simulation (test) | |
final <- matrix(NA,nrow=niter,ncol=3) | |
test <- vector(length=niter) | |
#Iterate through $niter simulations one at a time in a {for} loop |
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
#Manual calc of odds ratio: | |
#Pyrantel: 10 taken / 29 left | |
#Control 12 taken / 9 left | |
(10/29)/(12/9) #0.2586 | |
1/((10/29)/(12/9)) #3.87 (more intuitive) | |
log(0.2586) #On log scale -1.3524 |
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
############################################################# | |
## Permutation test for interaction between 2 main effects ## | |
############################################################# | |
#Based on http://r.789695.n4.nabble.com/Randomization-of-a-two-way-ANOVA-td874581.html | |
#Read in data | |
data <- read.csv('final.project.data.csv',h=T) | |
#Full model with interaction |
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
########################################################### | |
###### ####### | |
###### GET ACTUAL START/STOP TIMES ####### | |
###### ####### | |
########################################################### | |
#Read in input file | |
#Should be called startstop.csv and should be in same directory as the .dat files | |
#File should have three columns labeled start, stop, and plot (for plot names) | |
#Dates in start stop should be formatted e.g. 7/16/2014 13:12 |
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
#There isn't really an easy way to do this, unfortunately. | |
#In your stated example, the populations are ordered, so you should be able to calculate the mean in JAGS like this: | |
Pop1.mean <- mean(data[1:3,1:10]) | |
Pop2.mean <- mean(data[4:6,1:10]) | |
#but maybe your actual dataset isn't organized that way, and even if it was you'd have to | |
#manually go through the dataset to figure out the cutoffs. |
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
#Get a list of all individual text files | |
fnames <- list.files(pattern='\\.txt') | |
#Get number of individuals | |
ninds <- length(fnames) | |
#Make blank output data frame | |
output <- as.data.frame(matrix(NA,nrow=ninds,ncol=6)) | |
names(output) <- c('ID','PctSafe','PctRisky','Switches','FinalState','Fate') |
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
#Streamline process of reading in CSV and Shapefile data | |
#from Buffalo Open Data Portal (via Socrata API) | |
# | |
#Requires RSocrata, tidyverse, and sf | |
# | |
#read_bufdata() with no arguments for a list of possible dataset titles | |
read_bufdata <- function(title=NULL, format='CSV'){ | |
if ( ! format %in% c('CSV', 'csv', 'Shapefile', 'shapefile') ){ |
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
get_shapefile <- function(path){ | |
temp_dir <- tempdir() | |
dest_dir <- tempfile() | |
dir.create(dest_dir) | |
if(grepl('http',path)){ | |
dest <- paste0(dest_dir,"/",basename(path)) | |
utils::download.file(path, dest, quiet=T) | |
path <- dest | |
} |
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
cat("Applying occuMulti maxOrder patch\n") | |
fl_getY <- unmarked:::fl_getY | |
setMethod("fl_getY", "unmarkedFitOccuMulti", function(fit, ...){ | |
maxOrder <- fit@call$maxOrder | |
if(is.null(maxOrder)) maxOrder <- length(fit@data@ylist) | |
getDesign(getData(fit), fit@detformulas, fit@stateformulas, maxOrder)$y | |
}) | |
name_to_ind <- unmarked:::name_to_ind |
OlderNewer