Mutiple01

tidyHeatmap

## -- Attaching packages ------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.2.1     v purrr   0.3.3
## v tibble  2.1.3     v dplyr   0.8.4
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ---------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Loading required package: ComplexHeatmap
## Loading required package: grid
## ========================================
## ComplexHeatmap version 2.3.2
## Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
## Github page: https://github.com/jokergoo/ComplexHeatmap
## Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
## 
## If you use it in published research, please cite:
## Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
##   genomic data. Bioinformatics 2016.
## 
## This message can be suppressed by:
##   suppressPackageStartupMessages(library(ComplexHeatmap))
## ========================================
## 
## Attaching package: 'tidyHeatmap'
## The following object is masked from 'package:stats':
## 
##     heatmap
## # A tibble: 504 x 6
##    sample     symbol `count normalised adjust~ condition type       location    
##    <chr>      <fct>                      <int> <fct>     <fct>      <chr>       
##  1 treated1   Kal1                          37 treated   single-re~ Secretory   
##  2 treated2   Kal1                          41 treated   paired-end Secretory   
##  3 treated3   Kal1                          50 treated   paired-end Secretory   
##  4 untreated1 Kal1                        1127 untreated single-re~ Secretory   
##  5 untreated2 Kal1                        1046 untreated single-re~ Secretory   
##  6 untreated3 Kal1                         932 untreated paired-end Secretory   
##  7 untreated4 Kal1                        1018 untreated paired-end Secretory   
##  8 treated1   Ant2                        2331 treated   single-re~ Intracellul~
##  9 treated2   Ant2                        2478 treated   paired-end Intracellul~
## 10 treated3   Ant2                        2575 treated   paired-end Intracellul~
## # ... with 494 more rows

## Adding missing grouping variables: `location`

gensvm

## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
## The following object is masked from 'package:purrr':
## 
##     transpose
## Warning in require_bit64_if_needed(ans): Some columns are type 'integer64'
## but package bit64 is not installed. Those columns will print as strange
## looking floating point data. There is no need to reload the data. Simply
## install.packages('bit64') to obtain the integer64 print method and print the
## data again.
## [1] 1024   86
## Starting main loop.
## Dataset:
##  n = 973
##  m = 476
##  K = 3
## Parameters:
##  kappa = 0.000000
##  p = 1.000000
##  lambda = 0.0000000100000000
##  epsilon = 1e-006
## 
## iter = 0, L = 0.5576051664406462, Lbar = 6.8766950311224893, reldiff = 11.3325525748235220
## 
## Optimization finished, iter = 100, loss = 0.0029159207482829, reldiff = 0.0036775211440595
## Number of support vectors: 694
## Training time: 10.521264
##                     Length Class  Mode     
## call                  8    -none- call     
## p                     1    -none- numeric  
## lambda                1    -none- numeric  
## kappa                 1    -none- numeric  
## epsilon               1    -none- numeric  
## weights               1    -none- character
## kernel                1    -none- character
## gamma                 1    -none- numeric  
## coef                  1    -none- numeric  
## degree                1    -none- numeric  
## kernel.eigen.cutoff   1    -none- numeric  
## verbose               1    -none- numeric  
## random.seed           1    -none- numeric  
## max.iter              1    -none- numeric  
## n.objects             1    -none- numeric  
## n.features            1    -none- numeric  
## n.classes             1    -none- numeric  
## classes               3    -none- character
## V                   954    -none- numeric  
## n.iter                1    -none- numeric  
## n.support             1    -none- numeric  
## training.time         1    -none- numeric
## Data:
##  n.objects: 973 
##  n.features: 8 
##  n.classes: 3 
##  classes: 6R 7R 7U 
## Parameters:
##  p: 1 
##  lambda: 1e-08 
##  kappa: 0 
##  epsilon: 1e-06 
##  weights: unit 
##  max.iter: 100 
##  random.seed: 123 
##  kernel: rbf 
##  kernel.eigen.cutoff: 1e-08 
##  gamma: 10 
## Results:
##  time: 10.52126 
##  n.iter: 100 
##  n.support: 694

Random Forest

## 
##  randomForestSRC 2.9.3 
##  
##  Type rfsrc.news() to see new features, changes, and bug fixes. 
## 
## 
## Attaching package: 'randomForestSRC'
## The following object is masked from 'package:purrr':
## 
##     partial
## Warning in require_bit64_if_needed(ans): Some columns are type 'integer64'
## but package bit64 is not installed. Those columns will print as strange
## looking floating point data. There is no need to reload the data. Simply
## install.packages('bit64') to obtain the integer64 print method and print the
## data again.
## [1] 5334   86
##                          Sample size: 4881
##            Frequency of class labels: 698, 1626, 2557
##                      Number of trees: 1000
##            Forest terminal node size: 1
##        Average no. of terminal nodes: 94.025
## No. of variables tried at each split: 3
##               Total no. of variables: 8
##        Resampling used to grow trees: swor
##     Resample size used to grow trees: 3085
##                             Analysis: RF-C
##                               Family: class
##                       Splitting rule: gini *random*
##        Number of random split points: 10
##               Normalized brier score: 0.75 
##                                  AUC: 100 
##                           Error rate: 0, 0.01, 0, 0
## 
## Confusion matrix:
## 
##           predicted
##   observed  6R   7R   7U class.error
##         6R 694    0    4      0.0057
##         7R   0 1626    0      0.0000
##         7U   0    0 2557      0.0000
## 
##  Overall error rate: 0.08%
## [1] "Default_AADT" "HU"           "Pop"          "WAC"          "RAC"         
## [6] "Agg_Inc"      "Agg_Veh"      "Empl"

## no importance found: calculating it now ...
## done
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================| 100%

Air Crash

### from https://github.com/philjette/CrashData/blob/master/PlaneCrashes.R

startYear<-1920

library(XML)
library(stringr)

getData <-function(year){
  #url
  url<-paste("http://www.planecrashinfo.com/", year, "/", year, ".htm", sep="")  
  
  # Read and parse HTML file
  html.raw <- htmlTreeParse(url,useInternal = TRUE)
  html.parse<-unlist(xpathApply(html.raw, '//td', function(x)
    xpathSApply(x,".//text()", xmlValue)))
  
  #get rid of field names
  html.parse<-html.parse[5:length(html.parse)]
  
  #Get fields into vectors to prepare for data frame
  crashDates <- html.parse[seq(1, length(html.parse), 6)]
  crashLocation <- html.parse[seq(2, length(html.parse), 6)]
  crashOperator <- html.parse[seq(3, length(html.parse), 6)]
  crashType <- html.parse[seq(4, length(html.parse), 6)]
  crashOutcome <- html.parse[seq(6, length(html.parse), 6)]
  
  #compile into data.frame
  data<-data.frame(cbind(crashDates,crashLocation,crashOperator,crashType,crashOutcome))
  
  return(data)
  
}

#initialize data table
compiledData <-data.frame()

#loop through years and get data
for (i in startYear:2020) {
  compiledData <- rbind(compiledData, getData(i))
}

#split the crash outcome into passengers and fatalities
compiledData$crashF <- unlist(str_split(compiledData$crashOutcome, "\\/", n=2))[seq(1, length(compiledData$crashOutcome)*2, 2)]
compiledData$crashP <- unlist(str_split(compiledData$crashOutcome, "\\/", n=2))[seq(2, length(compiledData$crashOutcome)*2, 2)]
compiledData$crashP <- unlist(str_split(compiledData$crashP, "\\(", n=2))[seq(1, length(compiledData$crashP)*2, 2)]

#coerce fields to appropriate data types
compiledData$crashF <-as.numeric(compiledData$crashF)
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## [1] 4977    9
##   crashDates                      crashLocation            crashOperator
## 1 1908-09-17                Fort Myer, Virginia   Military - U.S. Army\n
## 2 1909-09-07            Juvisy-sur-Orge, France                      ?\n
## 3 1912-07-12          Atlantic City, New Jersey   Military - U.S. Navy\n
## 4 1913-08-06 Victoria, British Columbia, Canada                Private\n
## 5 1913-09-09                 Over the North Sea Military - German Navy\n
## 6 1913-10-17              Johannisthal, Germany Military - German Navy\n
##                crashType crashOutcome crashF crashP Prop crashYear
## 1       Wright Flyer III       1/2(0)      1      2  0.5      1908
## 2         Wright Byplane       1/1(0)      1      1  1.0      1909
## 3              Dirigible       5/5(0)      5      5  1.0      1912
## 4       Curtiss seaplane       1/1(0)      1      1  1.0      1913
## 5 Zeppelin L-1 (airship)     14/20(0)     14     20  0.7      1913
## 6 Zeppelin L-2 (airship)     30/30(0)     30     30  1.0      1913
## 
## 1908 1909 1912 1913 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 
##    1    1    1    3    2    5    7    4    9   18   12   13   13    7   11   13 
## 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 
##   20   36   39   26   33   28   28   31   41   50   34   56   30   25   27   38 
## 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 
##   44   56   74   88   82   77   67   69   75   65   69   61   57   53   66   68 
## 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 
##   66   70   60   78   63   55   62   60   58   65   69   73   58   77   64   58 
## 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 
##   51   57   63   51   60   45   50   54   48   48   56   50   54   64   83   61 
## 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 
##   69   66   56   74   60   68   56   59   62   63   58   55   62   46   45   38 
## 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 
##   43   50   46   40   36   26   25   23   18   23   15   16   13    2

2020-02-24