Posts

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...

Module # 5 assignment

 Question #1 a.  Null Hypothesis (H0): The machine is producing cookies according to the manufacturer's specifications, with a mean breaking strength of 70 pounds. Alternative Hypothesis (Ha): The machine is not producing cookies according to the manufacturer's specifications, with a mean breaking strength different from 70 pounds. b.  a <- 70 s <- 3.5 n <- 49 xbar <- 69.1 z <- (xbar - a) / (s / sqrt(n)) p_value <- 2 * pnorm(-abs(z)) alpha <- 0.05 if (p_value < alpha) {   cat("Reject the null hypothesis. There is evidence that the machine is not meeting the manufacturer's specifications.\n") } else {   cat("Fail to reject the null hypothesis. There is no evidence that the machine is not meeting the manufacturer's specifications.\n") } c.  The computed p-value is the probability of observing a sample mean as extreme as 69.1 pounds, assuming the null hypothesis is true. If the p-value is less than the significance level (0.05), ...

Module #4 Probability Theory

 A1. P(A) = P(B) + P(B1) = 10 + 20 = 30  A2. P(B) = P(A) + P(A1) = 10 + 20 = 30  A3. P(A or B) = P(A) + P(B) - P(A and B)          P(A and B) = 10          P (A or B) = P(A) + P(B) - P(A and B) = 30 + 30 - 10 = 50          Therefore, the probability of Event A or B is 50%.  A4. P(A or B) = P(A) + P(B)          P(A or B) = 30 + 30 = 60        Therefore, P(A or B) is 60%.    B1. True B2.  The answer is true because it is based on the application of Bayes' theorem. In this case, the question is asking for the probability that it will rain on the day of Jane's wedding (Event A1) given the weatherman's prediction of rain (Event B).  The calculation correctly takes into account the probabilities of it raining (P(A1)) and not raining (P(A2)), as well as the conditional probabilities of the weatherman correctly predic...