Posts

Showing posts from November, 2023

Module 12

  Module 12 ```R # Install and load necessary packages install.packages("forecast") library(forecast) # Create a data frame with the provided data data <- data.frame(   Month = month.abb,   Year_2012 = c(31.9, 27, 31.3, 31, 39.4, 40.7, 42.3, 49.5, 45, 50, 50.9, 58.5),   Year_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) ) # Convert the data to a time series object ts_data <- ts(cbind(data$Year_2012, data$Year_2013), start = c(2012, 1), frequency = 12) # Plot the time series plot(ts_data, main = "Student Credit Card Charges Over Time", xlab = "Month", ylab = "Charges", col = c("blue", "red"), lty = 1:2) # Apply exponential smoothing model fit <- ets(ts_data) summary(fit) ``` This code does the following: 1. Installs and loads the `forecast` package. 2. Creates a data frame with the provided data. 3. Converts the data frame into a time series object. 4. Plots a time series plot for the s...

Module 11

  Module 11 Assignment  **Question 10.1: Set up an additive model for the ashina data** To set up an additive model for the ashina data, you can follow these steps. The data contains additive effects on subjects, period, and treatment. We'll use linear models to compare the results with t-tests. ```R # Load the ISwR package library(ISwR) # Load the ashina data data(ashina) # Create a subject factor ashina$subject <- factor(1:16) # Attach the dataset for easier access attach(ashina) # Create data frames for active and placebo treatments act <- data.frame(vas = vas.active, subject, treat = 1, period = grp) plac <- data.frame(vas = vas.plac, subject, treat = 0, period = grp) # Fit linear models for active and placebo treatments model_act <- lm(vas ~ subject + period + treat, data = act) model_plac <- lm(vas ~ subject + period + treat, data = plac) # Compare the results with t-tests t_test_act <- t.test(vas.active ~ treat) t_test_plac <- t.test(vas.plac ~ trea...