Posts

Showing posts from October, 2023

Module #10 Assignment

 Question #1  # install.packages("car") library(car) # Load the dataset data("cystfibr") # Fit the linear regression model model <- lm(spemax ~ age + weight + bmp + fev1, data = cystfibr) # Perform ANOVA anova_result <- anova(model) # Display regression coefficients coefficients(model) # Print ANOVA results anova_result Interpretation:  The interpretation of the results would involve looking at the coefficients for each variable in the model. These coefficients represent the estimated change in the response variable "spemax" for a one-unit change in the corresponding predictor variable while holding other predictors constant. The ANOVA result tests the overall significance of the model. Question #2 # Load the dataset data("secher") # Fit a linear regression model for log-transformed birth weight model10 <- lm(log(bwt) ~ I(log(ad) + log(bpd)), data = secher) # Sum of regression coefficients sum_coefficients <- sum(coefficients(model10)...

Module #9 Assignment

 #1  # Create the data frame 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, 6000, 5000, 7000, 4000, 8000),   Purchased = c("No", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes") ) # Create a table simple_table <- data.frame(   Country = assignment_data$Country,   age = assignment_data$age,   salary = assignment_data$salary,   Purchased = assignment_data$Purchased ) # Print the table print(simple_table) #2  # Load the mtcars dataset data(mtcars) # Create a contingency table assignment9 <- table(mtcars$gear, mtcars$cyl, dnn = c("gears", "cylinders")) # Print the c...

Module #8 Assignment

 #1  First, let's analyze the first dataset regarding the effects of a drug on stress levels. We will perform an analysis of variance (ANOVA) to determine if there are significant differences in the reaction times among the three groups with different stress levels. Here's how you can perform the ANOVA analysis using R: # Create a data frame with the provided data data <- data.frame(   High_Stress = c(10, 9, 8, 9, 10, 8),   Moderate_Stress = c(8, 10, 6, 7, 8, 8),   Low_Stress = c(4, 6, 6, 4, 2, 2) ) # Perform one-way ANOVA result_anova <- aov(data ~ data.frame(Group = rep(c("High", "Moderate", "Low"), each = 6))) # Summary of ANOVA summary(result_anova) The output of this code will provide you with the following information, including Df (degrees of freedom), Sum Sq (sum of squares), Mean Sq (mean squares), F value, and Pr(>F):  Df Sum Sq Mean Sq F value  Pr(>F)    data.frame  2  52.33  26.165   21.96...

Module #7 Assignment

 1.  # Define the 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) # Create a linear regression model model <- lm(y ~ x) # Summary of the model to get coefficients summary(model) 1.1  The relationship model is y = a + bx, where y is the dependent variable (response), x is the independent variable (predictor), a is the intercept, and b is the coefficient of x. 1.2  intercept <- coef(model)[1] slope <- coef(model)[2] 2.  # Data visit <- data.frame(   discharge = c(3.600, 1.800, 3.333, 2.283, 4.533, 2.883),   waiting = c(79, 54, 74, 62, 85, 55) ) # Fit a simple linear regression model model2 <- lm(discharge ~ waiting, data = visit) 2.1  The relationship model is discharge = a + b * waiting where a is the intercept, and b is the slope. 2.2  intercept2 <- coef(model2)[1] slope2 <- coef(model2)[2] intercept2 # Value of a slope2     # Value of b 2.3  # P...

Module #6 Assignment

 A.  First, let's address the calculations for the populations and sampla data # Population data  population <- c(8, 14, 16, 10, 11) # a. Compute the mean of the population mean mean_population <- mean(population) mean_population  Now, for selecting a random sample of size 2 out of the five members, you can use 'sample()' function:  # b. Select a random sample of size 2 sample_size <- 2 random_sample <- sample(population, size = sample_size)  random_sample  Next, compute the mean and standard deviation of your sample:  mean_sample <-  mean(random_sample)  sd_sample <-  sd(random_sample)  mean_sample  sd_sample  Finally, compare the mean and standard deviation of your sample to the entire population:  #d. Compare the Mean and Standard deviation of your sample to the entire population  mean_comparison <- mean_sample == mean_population  sd_comparison <-  sd_sample == sd(populat...