2024-03-16

Slide with Data

summary(USArrests)
##      Murder          Assault         UrbanPop          Rape      
##  Min.   : 0.800   Min.   : 45.0   Min.   :32.00   Min.   : 7.30  
##  1st Qu.: 4.075   1st Qu.:109.0   1st Qu.:54.50   1st Qu.:15.07  
##  Median : 7.250   Median :159.0   Median :66.00   Median :20.10  
##  Mean   : 7.788   Mean   :170.8   Mean   :65.54   Mean   :21.23  
##  3rd Qu.:11.250   3rd Qu.:249.0   3rd Qu.:77.75   3rd Qu.:26.18  
##  Max.   :17.400   Max.   :337.0   Max.   :91.00   Max.   :46.00

Slide with Plotly

Slide with R code

x <- USArrests\(UrbanPop y <- USArrests\)Assault plot<-plot_ly( x= x, y=y, type= ‘scatter’) layout( plot, title= “Assault Arrests among the Urban Population”, xaxis= list(title= “Urban Population”), yaxis= list(title= “Assault”))

Slide with plotly

## No scatter3d mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: 'layout' objects don't have these attributes: 'zaxis'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'

Slide with ggplot

## Warning: Use of `USArrests$Assault` is discouraged.
## ℹ Use `Assault` instead.

Slide with math text in Latex

x= USArrests$Assault n= 50

The mean \(\bar{x}\) of Assault in the dataset is calculated with the following formula:

\(\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i\ \)

The mean \(\bar{x}\) of Assault in the dataset is calculated with the following formula: where \(x_i\) represents each individual observation of Assault Arrest.

Slide with ggplot

Slide with ggplot

Slide with math text in Latex

The sample correlation coefficient \(r\) between Assault arrests and Urban population in the dataset is calculated as:

\(r_{\text{Assault, UrbanPop}} = \frac{\sum_{i=1}^{n} (\text{Assault}_i - \bar{x}_{\text{Assault}})(\text{UrbanPop}_i - \bar{x}_{\text{UrbanPop}})}{\sqrt{\sum_{i=1}^{n} (\text{Assault}_i - \bar{x}_{\text{Assault}})^2 \sum_{i=1}^{n} (\text{UrbanPop}_i - \bar{x}_{\text{UrbanPop}})^2}}\)

where \(\text{UrbanPop}_i\) represents each individual observation of Urban population