This file contains hidden or 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
# IUCR codes for Ill. define for ifelse grepl below | |
# code found at # http://gis.chicagopolice.org/website/clearMap_crime_sums/crime_types.html | |
UCR01 = "0110|0130" | |
UCR02 = "0261|0262|0263|0264|0265|0266|0271|0272|0273|0274|0275|0281|0291|1753|1754" | |
UCR03 = "0312|0313|031A|031B|0320|0325|0326|0330|0331|0334|0337|033A|033B|0340" | |
UCR04A = "051A|051B|0520|0530|0550|0551|0552|0553|0555|0556|0557|0558" | |
UCR04B = "041A|041B|0420|0430|0450|0451|0452|0453|0461|0462|0479|0480|0481|0482|0483|0485|0488|0489|0490|0491|0492|0493|0495|0496|0497|0498" | |
# assert == VC by UCR code & append col GUCR for a global variable holding codes in long form for respective crimes | |
chicago_ds_2015_gte$GUCR = ifelse(grepl(UCR01, chicago_ds_2015_gte$IUCR), "UCR01", |
This file contains hidden or 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
Data Understanding (1-6) | |
#1. Industry data belongs to; 2. Observations and variables count: ; 3. Data types | |
#4. Levels: ; 5. Any negatives (when ecommerce data); 6 Find Nulls | |
#1 Industry data belongs to: | |
#2 Observations & Variable Count | |
```{r} | |
library(skimr); skim(df99) | |
library(psych); describe(df99) | |
summary(df99) |
This file contains hidden or 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
# lm -- -- -- -- -- -- -- -- -- -- 604 Linear Regression | |
# from Statistics 101: Linear Regression, Residual Analysis | |
# youtube.com/watch?v=gLENW2AdJWg | |
bill <- c( 34, 108, 64 , 88 , 99 , 51 ) | |
mean(bill) | |
tip <-c ( 5, 17, 11, 8, 14, 5 ) | |
mean(tip) | |
#correlation coefficient = covariance / co-standard-deviation |
This file contains hidden or 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(readxl) | |
library(tidyverse) | |
library(psych) | |
library(scales) | |
setwd("C:/Users/tradingbills/Documents/_exer/_data/math/wk4/") | |
# 1 compute the covariance | |
# COV = Sum( (x_i - x_bar) * (y-i -y_bar)) / N-1 | |
# COVARIANCE | |
covariance <- function(x,y){ |
This file contains hidden or 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
z_score <- function(x, m, sd){ | |
return ((x-m)/sd) | |
} | |
x_val <- function(z, m, sd){ | |
return (z*sd + m) | |
} | |
m <- 100 | |
sd <- 15 |
This file contains hidden or 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
Data Understanding (1-5) | |
1. Industry data belongs to: Ecommerce | |
2. Find count of observations and variables,(use glimpse): 51290 & 24 | |
3. Know data types (use glimpse) | |
4. Levels: (use glimpse) | |
5. See if any negatives (because this is ecommerce data) | |
```{r} | |
glimpse(df99) | |
summary(df99) | |
``` |
This file contains hidden or 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} | |
#set UCR codes for Chicago | |
# 2020 http://gis.chicagopolice.org/website/clearMap_crime_sums/crime_types.html | |
# 2021 http://directives.chicagopolice.org/forms/CPD-63.451_Table.pdf | |
# 2021 above from footer of http://directives.chicagopolice.org/directives/data/a7a57bf0-12d7196c-11f12-d71a-3c76ad6f2c11950a.html | |
# 2021 above search from | |
# 388v01::34:51 which | |
# 538, grepl | |
# Murder | |
UCR01 = "0110|0130" |
OlderNewer