Skip to content

Instantly share code, notes, and snippets.

View MilesMcBain's full-sized avatar

Miles McBain MilesMcBain

  • Queensland Fire and Emergency Services
  • Brisbane, Queensland
View GitHub Profile
---
title: "Expected Repsponse plot"
author: "Miles McBain"
date: "20 October 2016"
output: html_document
---
#Read Data
library(rgdal)
shp=readOGR('/home/milesmcbain/data/aep/vectors/ANT_EVA/GIS_EVA/EVA_Paddocks_201003.TAB', 'EVA_Paddocks_201003')
writeOGR(obj = shp,
dsn = 'EVA_Paddocks',
layer = 'EVA_Paddocks',
driver = "GeoJSON")
#Extract metadata
library(jsonlite)
library(readr)
na_block_idx <-cppFunction("NumericVector na_block_idx(LogicalVector complete_case_vec){
int n = complete_case_vec.size();
NumericVector na_block_idxs(n);
int block_counter = 0;
if(complete_case_vec[0] == TRUE){
na_block_idxs[0] = ++block_counter;
}else{
na_block_idxs[0] = 0;
}
```{r}
tb_cases_sep %>%
group_by(gender, year) %>%
summarise(total_cases = sum(num_cases, na.rm = T)) %>%
ggplot(aes(x = year, y = total_cases, colour = gender)) +
geom_point() + geom_path() +
ggtitle("Worldwide Tuberculosis Cases Over Time vs Patient Gender", subtitle = "Reported by the WHO")
```
simple_roc <- function(labels, scores){
labels <- labels[order(scores, decreasing=TRUE)]
data.frame(TPR=cumsum(labels)/sum(labels), FPR=cumsum(!labels)/sum(!labels), labels)
}
dates <- tribble(
~dob,
"10/06/1968",
"16/07/1969",
"01/07/1966",
"15/09/1977",
"29/01/1971",
"12/01/1960",
"05/10/1973",
"21/04/1972",
library(alr3)
library(purrr)
library(dplyr)
library(broom)
library(modelr)
challenger_data <- challeng
link <- c("logit", "probit", "cloglog")
formulas <- formulas(.response = ~ cbind(Fail, n-Fail),
dat <- readr::read_csv("municipality\n- Ticino\n>> Distretto di Bellinzona\n......5001 Arbedo-Castione\n......5002 Bellinzona\n......5003 Cadenazzo\n......5004 Camorino\n")
dat %>% mutate(municipality = gsub(pattern = '[\\.\\>]|^-',
replacement = "",
municipality)) %>%
separate(col = municipality,
sep = '(?<=[0-9])\\s',
into = c ("code","municipality"),
fill = "left")
@MilesMcBain
MilesMcBain / phone_number_munge.R
Created March 30, 2017 03:44
Munging and splitting phone numbers for upload. Without Excel!
library(readr)
library(tidyverse)
sra <- read_csv("sra (4).csv")
sra_mobs <-
sra %>%
mutate(phone_number = ifelse(grepl(pattern = "^4", x = `Mobile Phone`), yes = paste0("0",as.character(`Mobile Phone`)), no = `Mobile Phone`),
type = "Member"
) %>%
@MilesMcBain
MilesMcBain / happy_plots.rmd
Created June 15, 2017 13:41
Stop plots greying out in shiny/flex
```{r}
#Stop annoying greying out of plots while updating
shiny::tags$style(type="text/css", ".recalculating {opacity: 1.0;}")
```