Posts

Showing posts from March, 2024

Module 10

  The deliberate bug in the provided code is the use of && instead of & inside the for loop for determining outliers. The && operator evaluates only the first element of the logical vectors, which leads to incorrect outlier detection. Here's the corrected version of the function: r tukey_multiple <- function(x) {   outliers <- array(TRUE, dim = dim(x))   for (j in 1:ncol(x)) {     outliers[, j] <- outliers[, j] & tukey.outlier(x[, j])   }   outlier.vec <- vector(length = nrow(x))   for (i in 1:nrow(x)) {      outlier.vec[i] <- all(outliers[i, ])    }    return(outlier.vec)  } To test the corrected function, we can apply it to a sample dataset and observe if it returns the expected results without errors: r # Sample dataset set.seed(123) data <- matrix(rnorm(100), ncol = 5) # Applying the fixed function outliers <- tukey_multiple(data) print(outliers)

Module 9 Assignment

Title: Revealing Insights: Exploring Multi-Variable Visualization with the Iris Dataset

Assignment 9

 Step 1: Load the dataset R # Install and load necessary packages install.packages("ggplot2") library(ggplot2) # Load the mtcars dataset data(mtcars) Step 2: Basic Visualization For basic visualization without any package, you can use base R plotting functions. Let's create a scatter plot of miles per gallon (mpg) against horsepower (hp). R # Basic Scatter Plot plot(mtcars$hp, mtcars$mpg, main = "Scatter Plot of Horsepower vs. MPG",       xlab = "Horsepower", ylab = "Miles Per Gallon") Step 3: Lattice Visualization For lattice visualization, you can use the lattice package. Let's create a histogram of car weights (wt). R # Install and load the lattice package install.packages("lattice") library(lattice) # Lattice Histogram histogram(~wt, data = mtcars, main = "Histogram of Car Weights", xlab = "Weight") Step 4: ggplot2 Visualization Finally, for ggplot2 visualization, let's create a boxplot of miles per g...

Module 8 Assignment

Input/ Output, string manipulation, and plyr package  Analyzing Student Data in RStudio: A Step-by-Step Guide In this tutorial, we'll walk through the process of analyzing student data in RStudio. We'll cover importing the dataset, calculating the mean grade by sex, and accessing specific columns of the dataset. Let's dive in! Step 1: Import the Dataset First, we need to import the dataset into RStudio. We'll use the `read.table()` function to read the dataset from a text file. Replace `<Assignment.6.Dataset>.txt` with the correct file path and name for your dataset. ```R # Import the dataset Student <- read.table("<Assignment.6.Dataset>.txt", header = TRUE) ``` Step 2: Calculate Mean Grade by Sex Next, we'll calculate the mean grade for each category of sex using the `ddply()` function from the `plyr` package. ```R # Calculate mean grade by sex library(plyr) StudentAverage <- ddply(Student, "Sex", summarise, Grade_Average = mea...