Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 562986db3b | |||
| 8fe1967319 |
+19
-26
@@ -1,12 +1,13 @@
|
||||
library(readr)
|
||||
library(EnvStats)
|
||||
library(nortest)
|
||||
|
||||
# install.packages(c("readr", "EnvStats"))
|
||||
|
||||
# set working directory (relative path)
|
||||
setwd("~/Desktop/Data Analytics/Lab 1")
|
||||
|
||||
# paste function my beloved <3
|
||||
setwd(paste(getwd(), "Lab 1", sep="/"))
|
||||
pdf("all_plots.pdf", width = 8, height = 6)
|
||||
|
||||
# read data
|
||||
epi.data <- read_csv("epi_results_2024_pop_gdp.csv")
|
||||
@@ -20,9 +21,7 @@ summary(epi.data$epi_results_2024_pop_gdp.csv.new)
|
||||
# print values in variable
|
||||
epi.data$RLI.new
|
||||
|
||||
|
||||
######## Optional ########
|
||||
## If you want to reference the variable without using the dataframe:
|
||||
# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||
|
||||
# attach dataframe
|
||||
attach(epi.data)
|
||||
@@ -46,6 +45,15 @@ PHL <- epi.data$PHL.new
|
||||
|
||||
PHL
|
||||
|
||||
# no NAs
|
||||
RLI_noNA <- epi.data$RLI.new[!is.na(epi.data$RLI.new)];
|
||||
PHL_noNA <- epi.data$PHL.new[!is.na(epi.data$PHL.new)];
|
||||
|
||||
set.seed(1);
|
||||
RLI_sub <- sample(RLI_noNA, size = min(180, length(RLI_noNA)));
|
||||
RLI_new_sub <- RLI_sub; # only if you truly need a second alias
|
||||
|
||||
|
||||
# find NAs inv variavle - outputs vector of logical values, true if NA, false otherwise
|
||||
NAs <- is.na(PHL)
|
||||
|
||||
@@ -75,24 +83,7 @@ boxplot(RLI, PHL.above30, names = c("RHI","PHL"))
|
||||
# hist(RLI)
|
||||
|
||||
# define sequence of values over which to plot histogram
|
||||
# I have NO IDEA why this keep breaking but I just started using the range func
|
||||
rng <- range(RLI, na.rm = TRUE)
|
||||
lo <- floor(rng[1] / 5) * 5
|
||||
hi <- ceiling(rng[2] / 5) * 5
|
||||
brks <- seq(lo, hi, by = 1)
|
||||
|
||||
# WHY????? WHY IS IT BREAKING????
|
||||
# [1] "range 0 lo 0 hi 100 brks 50" "range 97.7 lo 0 hi 100 brks 50"
|
||||
# Error in freq && !equidist : 'length = 15' in coercion to 'logical(1)'
|
||||
# Calls: hist -> hist.default -> plot -> plot.histogram
|
||||
# Execution halted
|
||||
print(paste("range", rng, "lo", lo, "hi", hi, "brks", brks))
|
||||
|
||||
hist(RLI,
|
||||
breaks = brks,
|
||||
prob = TRUE)
|
||||
|
||||
x <- seq(20, 90, by = 5)
|
||||
x <- seq(0., 100., 10)
|
||||
|
||||
# histogram (frequency distribution) over range
|
||||
hist(RLI, x, breaks=brks, prob=TRUE)
|
||||
@@ -103,7 +94,7 @@ lines(density(RLI, na.rm=TRUE)) # or try bw=“SJ”
|
||||
# print rug
|
||||
rug(RLI)
|
||||
|
||||
x <- seq(5., 95., 5)
|
||||
x <- seq(0., 100., 5)
|
||||
|
||||
# histogram (frequency distribution) over rabge
|
||||
hist(RLI, breaks = "FD", prob=TRUE)
|
||||
@@ -156,8 +147,8 @@ qqnorm(x); qqline(x)
|
||||
|
||||
|
||||
# print quantile-quantile plot for variable with any theoretical distribution
|
||||
qqplot(rnorm(180), RLI.sub, xlab = "Q-Q plot for norm dsn")
|
||||
qqline(RLI.sub)
|
||||
qqplot(rnorm(180), RLI_sub, xlab = "Q-Q plot for norm dsn")
|
||||
qqline(RLI_sub)
|
||||
|
||||
# print quantile-quantile plot for 2 variables
|
||||
qqplot(RLI, PHL, xlab = "Q-Q plot for RHI vs PHL")
|
||||
@@ -191,3 +182,5 @@ wilcox.test(x,y)
|
||||
|
||||
var.test(x,y)
|
||||
t.test(x,y)
|
||||
|
||||
dev.off()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user