Posts

Module #13

Image
 For this assignment, I created a simple animation in R. My animation is attached.  First, I downloaded the animation package by Yihui Xie. Then, I created the animation loop:  > library(animation) > ani.options(interval = 0.1) > col.range <- terrain.colors(15) > saveGIF({ + layout(matrix(c(1, 2), 2, 1, byrow = TRUE)) + par(mar = c(2, 4, 2, 1)) + + for (i in 1:100) { + x <- seq(-10, 10, length.out = 100) + y <- sin(x + i / 10) * exp(-abs(i / 50)) + plot(x, y, type = 'l', col = col.range[i %% 15 + 1], ylim = c(-1, 1), main = "Sine Wave Progression", xlab = "X-axis", ylab = "Amplitude") + abline(h = 0, col = "gray") + + plot(1, type = "n", axes = FALSE, xlab = "", ylab = "", main = "Frame Number") + text(1, 1, labels = paste("Frame:", i), cex = 2) + } + + }, movie.name = "sine_wave_animation.gif", ani.width = 600, ani...

Final Project - Opioid Overdoses in Florida

Image
 For this project, I chose to research a troubling issue in the world today. Opioid addiction and overdose have been an ever-growing problem, leading to many deaths due to overdose. For my research, I used this dataset:  US Opioid Overdose Deaths (kaggle.com)  which includes the number of deaths from overdose for every US state from 1999-2014. For the purpose of this project, I chose to use the Florida statistics as my sample to establish a hypothesis.  My hypothesis:     H1: The number of opioid overdose deaths in Florida has significantly increased from the earlier period of 1999-2004 to the later period of 2009-2014.     H0: There is no significant difference in the number of opioid overdose deaths in Florida between the earlier period of 1999-2004 compared to the later period of 2009-2014. Related work: For this project I used my knowledge from Module 6, where the class learned how to conduct one sample t-tests, two sample t-tests, and pa...

Module #12 Assignment

Image
First, I assigned the credit card data to a data frame.: credit_card_data <- data.frame(   Month = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"),   `2012` = c(31.9, 27, 31.3, 31, 39.4, 40.7, 42.3, 49.5, 45, 50, 50.9, 58.5),   `2013` = c(39.4, 36.2, 40.5, 44.6, 46.8, 44.7, 52.2, 54, 48.8, 55.8, 58.7, 63.4)    Next I called on ggplot 2 and created the time series plot: library(ggplot2) credit_card_ts <- ts(t(credit_card_data[, -1]), start = c(2012, 1), frequency = 12) matplot(credit_card_ts, type = "l", lty = 1, col = 1:ncol(credit_card_ts),         xlab = "Time", ylab = "Charges", main = "Monthly Credit Card Charges") Next, I employed the exponential soothing model: credit_card_model <- HoltWinters(credit_card_ts, beta = FALSE, gamma = FALSE) print(credit_card_model) Holt-Winters e...

Module #11 Assignment

 11/6/2023 10.1 library(ISwR) data(ashina) data ashina$subject <- factor(1:16) attach(ashina) act <- data.frame(vas=vas.active, subject, treat=1, period=grp) plac <-data.frame(vas=vas.plac, subject, treat=0, period = grp) first I created the model:  additive_model <- aov(vas ~ treat + subject + period, data = rbind(act, plac)) > anova(additive_model) Analysis of Variance Table Response: vas Df Sum Sq Mean Sq F value Pr(>F) treat 1 14706 14706.1 10.413 0.005644 ** subject 15 51137 3409.2 2.414 0.049184 * Residuals 15 21184 1412.3 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > t_test_1 <- t.test(vas ~ treat, data = ashina, subset = period == 1) > t_test_2 <- t.test(vas ~ treat, data = act, subset = period == 2) 10.3 > model_1 <- lm(z ~ a * b) model_2 <- lm(z ~ a:b) Call: lm(formula = z ~ a * b) Coefficients: (Intercept) ...

Module #9 Assignment

  1. Your data.frame is > assignment_data <- data.frame( Country = c("France","Spain","Germany","Spain","Germany", "France","Spain","France","Germany","France"), age = c(44,27,30,38,40,35,52,48,45,37), salary = c(6000,5000,7000,4000,8000), Purchased=c("No","Yes","No","No","Yes", "Yes","No","Yes","No","Yes")) Generate simple table in R that consists of four rows: Country, age, salary and purchased. In order to make a table from the dataframe, I loaded the data.table package. This is the result: > setDT(assignment_data) > assignment_data Country age salary Purchased 1: France 44 6000 No 2: Spain 27 5000 Yes 3: Germany 30 7000 No 4: Spain 38 4000 No 5: Germany 40 8000 Yes 6: France 35 6000 Yes 7: Spain 52...

Module #8 Assignment

1.  Report on drug and stress level by using R. Provide a full summary report on the result of ANOVA testing and what does it mean. More specifically, report using the following R functions:   Df, Sum, Sq Mean, Sq, F value, Pr(>F ) I created a data frame with the function: > data <- data.frame( + ReactionTime = c(10, 9, 8, 9, 10, 8, 8, 10, 6, 7, 8, 8, 4, 6, 6, 4, 2, 2), + StressLevel = factor(rep(c("High Stress", "Moderate Stress", "Low Stress"), each = 6)) I then printed out the summary of the report using: > report <- aov(ReactionTime ~ StressLevel, data = data) > summary(report) Df Sum Sq Mean Sq F value Pr(>F) StressLevel 2 82.11 41.06 21.36 4.08e-05 *** Residuals 15 28.83 1.92 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 From the p-value it can be concluded that there are differences in reaction times between the stress levels. 2.1 The zelazo data (taken from textbo...

Module #7 Assignment

Image
10/9/2023 1.1 Define the relationship model between the  predictor  and the  response  variable: lm(formula = y ~ x, data = data) y is the response variable and x is the predictor variable. 1.2 Calculate the coefficients?   Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 19.206 15.691 1.224 0.2558 x 3.269 1.088 3.006 0.0169 * --- 2.1 Define the relationship model between  the predictor  and the  response variable . lm(discharge ~ waiting, data = visit) 2.2 Extract the parameters of the estimated regression equation with the  coefficients  function . > coefficients(model) (Intercept) waiting -1.53317418 0.06755757 2.3 Determine the fit of the  eruption  duration using the estimated regression equation. > estimated_eruption (Intercept) 3.871431 3.1 Examine the relationship Multi Regression Model as stated above and its Coefficients using 4 differen...