Posts

Showing posts from April, 2026

Assignment 12

Image
  In this assignment, I used R Markdown to create a document that combines written text, R code, and output in one place. R Markdown is useful because it allows for reproducible analysis, meaning the results automatically update whenever the code is changed. The introduction and narrative sections were written using Markdown, which is a simple formatting language that helps structure text clearly within the document. I also included both inline and displayed mathematical expressions using LaTeX. The inline expression ($\alpha + \beta = \gamma$) appears within a sentence, while the displayed equation ($y = mx + b$) is centered on its own line, demonstrating how R Markdown can present mathematical concepts effectively. The Summary Statistics Code: The first code chunk loads the built-in mtcars dataset and uses the summary() function to generate descriptive statistics. This includes values such as the minimum, maximum, mean, and median for each variable. The output is automatically ...

Assignment 11: Debugging and Defensive Programming in R

Image
  The tukey.outlier function identifies outliers in a numeric vector using the Tukey method. It calculates the first (Q1) and third (Q3) quartiles, computes the interquartile range (IQR), and then flags values below Q1 – 1.5*IQR or above Q3 + 1.5*IQR as outliers. The function returns a logical vector indicating which elements are outliers. The tukey_multiple function determines which rows of a numeric matrix are outliers in all columns . It begins with defensive checks to ensure the input is a numeric matrix, which helps prevent errors during execution. The function initializes a matrix of TRUE values with the same dimensions as x . It then loops through each column, applying the tukey.outlier function. The element-wise AND operator & ensures that only rows that are outliers in every column remain marked as TRUE . The function is tested on a 10×5 random numeric matrix generated with rnorm . The set.seed ensures reproducibility. Running tukey_multiple on the test matrix...