Professional Documents
Culture Documents
Assignment2_2020154106
Assignment2_2020154106
Assignment2_2020154106
Amogelang Seipone
2024-03-16
R Markdown
Question 1
# Defining the coefficients matrix and the constant vector
coefficients <- matrix(c(2, -1, 3, 3, 2, -5, 1, 4, 2), ncol = 3, byrow =
TRUE)
constants <- c(4, 5, 3)
Question 2
# Generating random samples
set.seed(123) # Set seed for reproducibility
sample_size <- c(1000, 100000, 500000)
x1 <- runif(sample_size[1], min = 0, max = 1)
x2 <- runif(sample_size[2], min = 0, max = 1)
x3 <- runif(sample_size[3], min = 0, max = 1)
## [1] 0.4972778
mean_x2
## [1] 0.4993165
mean_x3
## [1] 0.4997863
## [1] "x3"
#Explanation of Findings:
# The mean of x1 is mean_x1, the mean of x2 is mean_x2, and the mean of x3 is
mean_x3.
# We calculated the absolute differences between each mean and the target
value of 0.5.
# After comparing these differences, we found that the mean closest to 0.5 is
from the sample closest_mean.
# This means that the sample size that provided the mean closest to 0.5 is
closest_mean.*
Question 3
# Loading the dataset from the "datasets" package
library(datasets)
data(mtcars)