Make Up Cat
Make Up Cat
BDATC01/0843/2022
2025-01-11
R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring
HTML, PDF, and MS Word documents. For more details on using R Markdown see
http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content
as well as the output of any embedded R code chunks within the document. You can
embed an R code chunk like this:
# Part i) Simulate the scenario
set.seed(123)
# Setting seed for reproducibility
n_questions <- 20
prob_correct <- 0.6
simulated_results <- rbinom(1, n_questions, prob_correct)
cat("Simulated number of correct guesses:", simulated_results, "\n")
# Part iii) Estimate the number of correct guesses with 99% probability of
occurrence
lower_bound <- qbinom(0.005, n_questions, prob_correct)
upper_bound <- qbinom(0.995, n_questions, prob_correct)
cat("Number of correct guesses with 99% probability of occurrence:",
lower_bound, "to", upper_bound, "\n")
# Example usage
x <- seq(0, 2 * pi, length.out = 100)
n_terms <- 10
fourier_series <- generate_fourier_series(x, n_terms)
library(regclass)
##
## Attaching package: 'VGAM'
## randomForest 4.7-1.2
# Assumption 1: Linearity
# Plot residuals vs fitted values
plot(model$fitted.values, model$residuals,
main = "Residuals vs Fitted Values",
xlab = "Fitted Values", ylab = "Residuals")
abline(h = 0, col = "red")
# Assumption 2: Independence
# Durbin-Watson test for autocorrelation
dw_test <- durbinWatsonTest(model)
# Assumption 3: No multicollinearity
# Variance Inflation Factor (VIF)
vif_values <- vif(model)
cat("VIF values:\n")
## VIF values:
print(vif_values)
## Girth Height
## 1.36921 1.36921
# Function to accept three vectors Y and X1, fit a linear regression model,
and compute the statistic L
compute_statistic_L <- function(Y, X1) {
# Fit the linear regression model
model <- lm(Y ~ X1)
# Extract coefficients
beta0 <- coef(model)[1]
beta1 <- coef(model)[2]
# Compute residuals
residuals <- Y - (beta0 + beta1 * X1)
# Compute S^2
S2 <- sum((Y - mean(Y))^2) / (length(Y) - 1)
# Compute L
L <- sum(residuals^2) / S2
return(L)
}
# Example usage
Y <- c(10, 20, 30, 40, 50)
X1 <- c(1, 2, 3, 4, 5)
L <- compute_statistic_L(Y, X1)
cat("Computed statistic L:", L, "\n")