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
--- | |
title: "Expected Repsponse plot" | |
author: "Miles McBain" | |
date: "20 October 2016" | |
output: html_document | |
--- | |
#Read Data |
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(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) |
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
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; | |
} |
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
```{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") | |
``` |
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
simple_roc <- function(labels, scores){ | |
labels <- labels[order(scores, decreasing=TRUE)] | |
data.frame(TPR=cumsum(labels)/sum(labels), FPR=cumsum(!labels)/sum(!labels), labels) | |
} |
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
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", |
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(alr3) | |
library(purrr) | |
library(dplyr) | |
library(broom) | |
library(modelr) | |
challenger_data <- challeng | |
link <- c("logit", "probit", "cloglog") | |
formulas <- formulas(.response = ~ cbind(Fail, n-Fail), |
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
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") |
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(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" | |
) %>% |
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
```{r} | |
#Stop annoying greying out of plots while updating | |
shiny::tags$style(type="text/css", ".recalculating {opacity: 1.0;}") | |
``` |