library(readr)
SDoH_Data_2018_2022_in_ <- read_csv("C:/Users/crist/Downloads/SDoH Data 2018_2022(in).csv")
## Rows: 254 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Year, Geography, Uninsured below 20%, Vacant housing below 20%
## dbl (2): Households living below the federal poverty level %, Population 25 ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(SDoH_Data_2018_2022_in_)
#example Data
data <- c(4, 8, 6, 5, 3, 7)
#Calculating Mean
mean_data <- mean(data)
print(mean_data)
## [1] 5.5
#Sorting data
sorted_data <- sort(data)
#Calculating median
median_data <- median(sorted_data)
print(median_data)
## [1] 5.5
#example data
data <- c(4, 4, 6, 5, 4, 7)
# calculating mode
# R does not have a built-in mode function, so we create one
mode_data <- function(x) {
uniqx <- unique(x)
uniqx[which.max(tabulate(match(x, uniqx)))]
}
# print mode
print(mode_data(data))
## [1] 4
# example data
data <- c(4, 8, 6, 5, 3, 7)
# calculating range
range_value <- max(data) - min(data)
print(range_value)
## [1] 5
# calculating IQR
iqr_value <- IQR(data)
print(iqr_value)
## [1] 2.5
# calculating variance
variance_data <- var(data)
print(variance_data)
## [1] 3.5
# calculating standard deviation
std_deviation <- sd(data)
print(std_deviation)
## [1] 1.870829
# Install e1071 package if it's not already installed
if (!require(e1071)) install.packages("e1071")
## Loading required package: e1071
# Load the e1071 package
library(e1071)
# generating example data
set.seed(123) # for reproductivity
data_normal <- rnorm(1000) #normally distrubted data
data_skewed <- rexp(1000, 2) #positively skewed data
#calculating skewness
skewness_normal <- skewness(data_normal)
skewness_skewed <- skewness(data_skewed)
#calculating Kurtosis
kurtosis_normal <- kurtosis(data_normal)
kurtosis_skewed <- kurtosis(data_skewed)
#printing results
print(paste("Skewness (Normal Distribution):", skewness_normal))
## [1] "Skewness (Normal Distribution): 0.0651959979701102"
print(paste("Skewness (Skewed Distribution):", skewness_skewed))
## [1] "Skewness (Skewed Distribution): 1.6855398530975"
print(paste("Kurtosis (Normal Distribution):", kurtosis_normal))
## [1] "Kurtosis (Normal Distribution): -0.080102010098833"
print(paste("Kurtosis (Skewed Distribution):", kurtosis_skewed))
## [1] "Kurtosis (Skewed Distribution): 3.07459056618157"
Data <- read_csv("C:/Users/crist/Downloads/SDoH Data 2018_2022(in).csv")
## Rows: 254 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Year, Geography, Uninsured below 20%, Vacant housing below 20%
## dbl (2): Households living below the federal poverty level %, Population 25 ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Data <- read_csv("C:/Users/crist/Downloads/SDoH Data 2018_2022(in).csv")
## Rows: 254 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Year, Geography, Uninsured below 20%, Vacant housing below 20%
## dbl (2): Households living below the federal poverty level %, Population 25 ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Calculate Mean: Households living below the federal poverty level %
mean_value <- mean(SDoH_Data_2018_2022_in_$`Households living below the federal poverty level %`)
print(mean_value)
## [1] 11.51614
#Calculate Median: Households living below the federal poverty level %
median_value <- median(SDoH_Data_2018_2022_in_$`Households living below the federal poverty level %`)
print(median_value)
## [1] 10.8
#Calculate Standard Deviation: Households living below the federal poverty level %
sd_value <- sd(SDoH_Data_2018_2022_in_$`Households living below the federal poverty level %`)
print(sd_value)
## [1] 5.992546
#Calculate Mean, Median & Standard Deviation: Population 25 years and older w/o HS diploma %
mean_value <- mean(SDoH_Data_2018_2022_in_$`Population 25 years and older w/o HS diploma %`)
print(mean_value)
## [1] 17.05039
median_value <- median(SDoH_Data_2018_2022_in_$`Population 25 years and older w/o HS diploma %`)
print(median_value)
## [1] 15.3
sd_value <- sd(SDoH_Data_2018_2022_in_$`Population 25 years and older w/o HS diploma %`)
print(sd_value)
## [1] 7.853706
#Calculate Mode: Uninsured below 20%
calculate_mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
# Use the custom function to find the mode of the variable
mode_value <- calculate_mode(SDoH_Data_2018_2022_in_$`Uninsured below 20%`)
# Print the mode
print(mode_value)
## [1] "Yes"
#Calculate Mode: Vacant housing below 20%
calculate_mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
# Use the custom function to find the mode of the variable
mode_value <- calculate_mode(SDoH_Data_2018_2022_in_$`Vacant housing below 20%`)
# Print the mode
print(mode_value)
## [1] "Yes"
#Calculate the Normal Distribution: Households living below the federal poverty level %
skew_value <- skewness(SDoH_Data_2018_2022_in_$`Households living below the federal poverty level %`)
# Print the skewness value
print(skew_value)
## [1] 1.034012
kurtosis_value <- kurtosis(SDoH_Data_2018_2022_in_$`Households living below the federal poverty level %`)
# Print the kurtosis value
print(kurtosis_value)
## [1] 1.783877
#Calculate the Normal distribution: Population 25 years and older w/o HS diploma %
skew_value <- skewness(SDoH_Data_2018_2022_in_$`Population 25 years and older w/o HS diploma %`)
# Print the skewness value
print(skew_value)
## [1] 1.707031
kurtosis_value <- kurtosis(SDoH_Data_2018_2022_in_$`Population 25 years and older w/o HS diploma %`)
# Print the kurtosis value
print(kurtosis_value)
## [1] 6.068097
```