Posts

Showing posts from November, 2024

Module 12. Assignment

Image
> Charge<-c(31.9,27,31.3,31,39.4,40.7,42.3,49.5,45,50,50.9,58.5,39.4,36.2,40.5,44.6,46.8,44.7,52.2,54,48.8 ,55.8,58.7,63.4) > Chargetimeseries <-ts(Charge) > Chargetimeseries <-ts(Charge,frequency=12,start=c(2012,1)) > Chargetimeseries Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2012 31.9 27.0 31.3 31.0 39.4 40.7 42.3 49.5 45.0 50.0 50.9 58.5 2013 39.4 36.2 40.5 44.6 46.8 44.7 52.2 54.0 48.8 55.8 58.7 63.4 > Chargeforecast<-HoltWinters(Chargetimeseries) > summary(Chargeforecast) Length Class Mode fitted 48 mts numeric x 24 ts numeric alpha 1 -none- numeric beta 1 -none- numeric gamma 1 -none- numeric coefficients 14 -none- numeric seasonal 1 -none- character SSE 1 -none- numeric call 2 -none- call > plot(Chargeforecast) Alpha is how the model reacts to the data. Beta controls the trend...

Module 11. Assignment

Question 1: > library(ISwR) > data(ashina) > ashina$subject <- factor(1:16) > act <- data.frame(vas = ashina$vas.active, subject = ashina$subject, treat = 1, period = ashina$grp) > plac <- data.frame(vas = ashina$vas.plac, subject = ashina$subject, treat = 0, period = ashina$grp) > combined_data <- rbind(act, plac) > model <- lm(vas ~ subject + treat + period, data = combined_data) > summary(model) Call: lm(formula = vas ~ subject + treat + period, data = combined_data) Residuals: Min 1Q Median 3Q Max -48.94 -18.44 0.00 18.44 48.94 Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(>|t|) (Intercept) -113.06 27.39 -4.128 0.000895 *** subject2 51.50 37.58 1.370 0.190721 subject3 121.50 37.58 3.233 0.005573 ** subject4 97.00 37.58 2.581 0.020867 * subject5 125.00 37.58 3.326 0.004604 ** subject6 31.50 ...

Module 10. Assignment

Question 1: > library(ISwR) > data("cystfibr") > model <-lm(pemax ~ age + weight + bmp + fev1, data = cystfibr) > anova_results <- anova(model) > anova_results Analysis of Variance Table Response: pemax Df Sum Sq Mean Sq age 1 10098.5 10098.5 weight 1 945.2 945.2 bmp 1 2379.7 2379.7 fev1 1 2455.6 2455.6 Residuals 20 10953.7 547.7 F value Pr(>F) age 18.4385 0.0003538 *** weight 1.7258 0.2038195 bmp 4.3450 0.0501483 . fev1 4.4836 0.0469468 * Residuals --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > summary(model) Call: lm(formula = pemax ~ age + weight + bmp + fev1, data = cystfibr) Residuals: Min 1Q Median 3Q -42.521 -10.885 3.003 15.488 Max 41.767 Coefficients: Estimate Std. Error (Intercept) 179.2957 61.8855 age -3.4181 3.3086 weight 2.6882 ...

Module 9. Assignment

Question 1:      Generate (1) a one-way table for "purchased" > purchased <-c("No", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes") > results <- table(purchased) > results purchased No Yes 5 5      a two-way table for "country" and "purchased". > country <-c("France", "Spain", "Germany", "Spain", "Germany", "France", "Spain", "France", "Germany", "France") > purchased <-c("No", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes") > results <- table(country, purchased) > results purchased country No Yes France 1 3 Germany 2 1 Spain 2 1 Question 2: Generate Contingency table a...