Rlab
Rlab
A:
# Generate random data
data_group1 <- rnorm(50, mean = 10, sd = 2)
data_group2 <- rnorm(50, mean = 12, sd = 2)
# Descriptive statistics
mean_group1 <- mean(data_group1)
mean_group2 <- mean(data_group2)
sd_group1 <- sd(data_group1)
sd_group2 <- sd(data_group2)
# T-test
t_test_result <- t.test(data_group1, data_group2)
# Display results
cat("Descriptive Statistics:\n")
cat("Group 1 - Mean:", mean_group1, "SD:", sd_group1, "\n")
cat("Group 2 - Mean:", mean_group2, "SD:", sd_group2, "\n\n")
cat("T-Test Results:\n")
cat("t-value:", t_test_result$statistic, "\n")
cat("p-value:", t_test_result$p.value, "\n")
# Plot histogram
hist(data_group1, main = "Group 1 Histogram", xlab = "Values", col = "lightblue")
hist(data_group2, main = "Group 2 Histogram", xlab = "Values", col = "lightgreen")
7.B:
# Generate some example data
set.seed(123)
x <- rnorm(100, mean = 10, sd = 2)
y <- 3 * x + rnorm(100, mean = 0, sd = 5)
# Display predictions
cat("Predictions:\n", predictions)
8.A
# Load the Iris dataset
data(iris)
# Calculate accuracy
accuracy <- sum(diag(confusion_matrix)) / sum(confusion_matrix)
cat("Accuracy:", accuracy, "\n")
8.B:
# Load the Iris dataset
data(iris)
9.
# Install and load necessary packages
if (!requireNamespace("recommenderlab", quietly = TRUE))
install.packages("recommenderlab")
library(recommenderlab)
10.
# Install necessary packages
if (!requireNamespace("SentimentAnalysis", quietly = TRUE))
install.packages("SentimentAnalysis")
if (!requireNamespace("SnowballC", quietly = TRUE)) install.packages("SnowballC")
# Load packages
library(SentimentAnalysis)
# Display sentiments
print(sentiments)
11.
# Install and load necessary packages
if (!requireNamespace("randomForest", quietly = TRUE)) install.packages("randomForest")
if (!requireNamespace("mlbench", quietly = TRUE)) install.packages("mlbench")
library(randomForest)
library(mlbench)
# Generate example time series data (replace this with your own sales data)
set.seed(123)
sales_data <- ts(rnorm(100, mean = 100, sd = 10), start = 1)
# Forecast sales for the nearby future (adjust 'h' based on your prediction horizon)
forecast_values <- forecast(best_model, h = 10)