https://us02web.zoom.us/meeting/register/RQW4PGPcT0ixadrHwD0-aQ#/registration
geom_histogramboundary instead of center sets the edgeboundary instead of center sets the edgekernel density estimation or kde \[
p(x|{x_i}) = \frac{1}{nb_W}\sum_{i=1}^n K\left(\frac{x-x_i}{b_W}\right)
\]| Method | Code | Description |
|---|---|---|
| Silverman’s Rule | bw = "nrd0" |
Assume Gaussian |
| Scott’s Rule | bw = "nrd" |
Assume Gaussian |
| Cross-Validation | bw = "ucv" |
CV error |
| Sheather-Jones | bw = "sj" |
RMSE based on curvature |
kernel arg
gaussian, rectangular, triangular, epanechnikov, biweight, cosine, optcosinenyc_bnb |> ggplot(aes(revenue)) +
geom_density(color = palette_OkabeIto[1],
fill = darken(palette_OkabeIto[1],-0.3),
bounds = c(0,Inf)) +
scale_x_continuous(limits = c(-50,1000)) +
theme_minimal(base_size = 16) +
labs(title = "Revenue Per Month",
subtitle = "Why is the density non-zero for negative revenue?",
x = "Revenue")stat-ecdfstat_qqstat_qq_lineUScereal = UScereal |> mutate(outlier = if_else(fibre>20,"Outlier","Normal"))
UScereal = UScereal |> mutate(inlier = if_else(fibre == 0,"Inlier","Normal"))
UScereal |> ggplot(aes(sample=fibre)) +
labs(title="QQ-Plot Fibre Content in US Cereal Brands",
x="Theoretical Quantile",
y="Fibre Content") +
theme_minimal(base_size=16) +
coord_cartesian(ylim = c(-0.1, 35)) +
stat_qq(size = 3) +
stat_qq_line(color="red") +
annotate("rect",xmin=-2.5,xmax=-0.6,ymin=-1,ymax=2,,alpha = .2,linewidth=1,fill="orange") +
annotate("text",x=-2,y=4,label="Potential Inliers",size = 8)nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side")
nyc_bnb |> filter(neighborhood %in% nb_vec) |>
ggplot(aes(x=revenue)) +
geom_histogram() +
facet_wrap(~neighborhood,scales="free_y") +
theme_minimal(base_size=16) +
scale_x_continuous(limits=c(0,1000)) +
labs(title="Revenue Distributions in 4 NYC Neighborhoods",
x="Revenue")nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side")
nyc_bnb |> filter(neighborhood %in% nb_vec) |>
ggplot(aes(x=revenue,group = neighborhood,fill = neighborhood,color=neighborhood)) +
geom_density(alpha=0.4) +
scale_fill_OkabeIto() +
scale_color_OkabeIto() +
theme_minimal(base_size=16) +
scale_x_continuous(limits=c(0,1000)) +
labs(title="Revenue Distributions in 4 NYC Neighborhoods",
x="Revenue")nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side","Bedford-Stuyvesant","Astoria")
nyc_bnb |> filter(neighborhood %in% nb_vec, revenue < 1000) |>
ggplot(aes(x=revenue,y = neighborhood)) +
coord_cartesian(xlim = c(0,500)) +
geom_boxplot() +
theme_minimal(base_size=16) +
labs(title="Revenue per Night in 6 NYC Neighborhoods",
x="Revenue per Night ($)",y="Neighborhood")nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side","Bedford-Stuyvesant","Astoria")
nyc_bnb |> filter(neighborhood %in% nb_vec, revenue < 1000) |>
ggplot(aes(x=revenue,y = neighborhood)) +
coord_cartesian(xlim = c(0,500)) +
geom_violin(fill = "grey80") +
theme_minimal(base_size=16) +
labs(title="Revenue per Night in 6 NYC Neighborhoods",
x="Revenue per Night ($)",y="Neighborhood")nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side","Bedford-Stuyvesant","Astoria")
nyc_bnb |> filter(neighborhood %in% nb_vec, revenue < 1000) |>
ggplot(aes(x=revenue,y = neighborhood)) +
coord_cartesian(xlim = c(0,500)) +
geom_jitter(height = 0.3, width = 0, size = 0.5, alpha = 0.2) +
theme_minimal(base_size=16) +
labs(title="Revenue per Night in 6 NYC Neighborhoods",
x="Revenue per Night ($)",y="Neighborhood")library(ggforce)
nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side","Bedford-Stuyvesant","Astoria")
nyc_bnb |> filter(neighborhood %in% nb_vec, revenue < 1000) |>
ggplot(aes(x=revenue,y = neighborhood)) +
coord_cartesian(xlim = c(0,500)) +
geom_violin(color = NA, fill = "grey90") +
geom_sina(size = 0.5, alpha = 0.3) +
theme_minimal(base_size=16) +
labs(title="Revenue per Night in 6 NYC Neighborhoods",
x="Revenue per Night ($)",y="Neighborhood")library(ggridges)
nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side","Bedford-Stuyvesant","Astoria")
nyc_bnb |> filter(neighborhood %in% nb_vec) |>
ggplot(aes(x=reviews_per_month,y = neighborhood)) +
scale_x_continuous(limits = c(0,3)) +
geom_density_ridges(rel_min_height=0.05,alpha=0.4) +
theme_minimal(base_size=16) +
labs(title="Reviews Per Month in 4 NYC Neighborhoods",
x="Reviews Per Month",y="Neighborhood")log Scalelog Scalelibrary(ggridges)
nb_vec = c("Williamsburg","West Village","Park Slope","Upper East Side","Bedford-Stuyvesant","Astoria")
nyc_bnb |> filter(neighborhood %in% nb_vec, revenue > 0, revenue < 1000) |>
ggplot(aes(x=revenue,y = neighborhood)) +
scale_x_log10(breaks = c(10, 100, 1000), labels = c("$10", "$100", "$1,000")) +
coord_cartesian(xlim = c(2, 1000)) +
geom_density_ridges(rel_min_height=0.05,alpha=0.4) +
theme_minimal(base_size=16) +
labs(title="Revenue per Night in 6 NYC Neighborhoods",
x="Revenue per Night ($)",y="Neighborhood")nb_vec = c("West Village","Upper East Side","Bedford-Stuyvesant")
nyc_bnb |> filter(neighborhood %in% nb_vec, revenue > 0, revenue < 1000) |>
ggplot(aes(x=revenue, color = fct_reorder(neighborhood, revenue, median))) +
stat_ecdf(geom = "step", linewidth = 1) +
scale_x_log10(breaks = c(10, 100, 1000), labels = c("$10", "$100", "$1,000")) +
coord_cartesian(xlim = c(2, 1000)) +
scale_color_OkabeIto() +
theme_minimal(base_size=16) +
labs(title="Revenue per Night in 3 NYC Neighborhoods",
x="Revenue per Night ($)",y="Fraction of Listings",color="Neighborhood")