Posts

Showing posts from October, 2023

Module #10 Assignment

  Module 18 Assignment 9.1 Analysis of Variance (ANOVA) and Regression Coefficients: To conduct an ANOVA and interpret the coefficients for the model using the "cystfiber" data, use: if (!exists("cystfiber")) {   data("cystfibr") } model <- lm(formula = spemax ~ age + weight + bmp + fev1, data = cystfiber) anova_result <- anova(model) print(anova_result) coefficients(model) If the "cystfibr" data hasn't previously been loaded, this code loads it first. We then used the above formula to fit a linear regression model. To perform an ANOVA and present the findings, we utilize the anova function. Lastly, we use the coefficients function to print the regression coefficients. 9.2 Analysis of Log-Transformed Data and Regression Coefficients: To analyze log-transformed data ad regression coefficients, you can log-transform the birth weight, as well as the abdominal and biparietal diameters, from the "secher" data. if (!exists("sec...

Module #9 Assignment

Image
  Module #9 Assignment Generating a simple table for the given data.frame assignment_data: simple_table <- assignment_data[, c("Country", "age", "salary", "Purchased")] Generating a contingency table using the mtcars dataset: assignment9 <- table(mtcars$gear, mtcars$cyl, dnn = c("gears", "cylinders")) 2.1. Adding row and column totals to the assignment9 table using addmargins: assignment9_with_totals <- addmargins(assignment9) 2.2. Calculating proportional weights of each value in the assignment9 table using prop.tables: proportional_weights <- prop.table(assignment9) 2.3. Calculating row proportions in the assignment9 table using prop.table with margin = 1: row_proportions <- prop.table(assignment9, margin = 1) Code & Table: assignment_data <- data.frame(   Country = c("France", "Spain", "Germany", "Spain", "Germany", "France", "Spain"...

Module #8 Assignment

  Module 8 Assignment Use the following to conduct an analysis of variance (ANOVA) in R to examine how the medicine affects stress levels: data <- data.frame(   StressLevel = factor(rep(c("High Stress", "Moderate Stress", "Low Stress"), each = 6)),   StressRating = c(10, 9, 8, 9, 10, 8, 8, 10, 6, 7, 8, 8, 4, 6, 6, 4, 2, 2) ) model <- aov(StressRating ~ StressLevel, data = data) summary(model) By grouping individuals into one of three stress levels and using the "aov" function to do an analysis of variance (ANOVA) with the stress rating as the dependent variable and the stress level as the independent variable, the aforementioned code will construct a data frame with the given data. The summary(model) output will include the following relevant information: Df: Degrees of freedom , which represents the number of groups (levels of the independent variable) and the error degrees of freedom. Sum Sq: The sum of squares , which measures the total ...

Module #7 Assignment

Module 7 Assignment 1.1) Defining the relationship model between the predictor and the response variable: The relationship model between the predictor (X) and the response variable (Y) is defined as: Y = a + bX + e Y = dependent variable (what is being predicted or explained). X = independent variable (what is predicting or explaining the value of Y). a = constant, representing the value of Y when X = 0. b = coefficient of X, indicating the slope of the regression line, i.e., how much Y changes for each one-unit change in X. e = the error term, which represents the error in predicting the value of Y given the value of X. 1.2) Calculating the coefficients: To calculate the coefficients (a and b) for the given data: x <- c(16, 17, 13, 18, 12, 14, 19, 11, 11, 10) y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48) model <- lm(y ~ x) a <- coef(model)[1] # Intercept (a) b <- coef(model)[2] # Slope (b) cat("Intercept (a):", a, "\n") cat("Slope (b):", b...