Posts

Showing posts from February, 2026

Module 6: Matrix Operations in R

Image
     In this assignment, I practiced basic matrix operations in R, including addition, subtraction, and creating special matrices using the diag() function. These skills are important for understanding linear algebra concepts in data analysis and statistics. The topics are connected to matrix operations discussed in The Art of R Programming  and good coding practices from R Packages.    Question 1 :  Consider A=matrix(c(2,0,1,3), ncol=2) and B=matrix(c(5,2,4,-1), ncol=2). a) Find A + B b) Find A - B First, I created two matrices:      Matrix addition and subtraction are done element-by-element, as long as both matrices have the same dimensions. Question 2 :  Using the diag() function to build a matrix of size 4 with the following values in the diagonal 4,1,2,3. Next, I created a 4×4 matrix with values 4, 1, 2, and 3 on the diagonal.                 The diag() function places the given va...

Module 5: Determinant and Inverse of Matrices in R

Image
 This assignment practiced creating matrices in R and computing a determinant and inverse (when possible).   Step 1: Creating Matrices A and B   I created the matrices using matrix() :    Matrix A contains the numbers 1 to 100 arranged into 10 rows. Matrix B contains the numbers 1 to 1000 arranged into 10 rows.    Step 2: Checking the Dimensions To check the size of each matrix, I used: Step 3: Finding the Determinant of A I used the det() function to find the determinant of A: This result shows that matrix A is singular , which means it does not have an inverse.    Step 4: Finding the Inverse of A I attempted to find the inverse of A using:   Result: R returned an error saying that the system is computationally singular. This confirms that A does not have an inverse because its determinant is zero.   Step 5: Testing Matrix B Since B is not a square matrix, I tested:     Result: Both commands returned errors. This...

Hospital Patient Blood Pressure Analysis: Boxplots and Histogram

Image
       For this assignment, I analyzed hospital patient data to examine how blood pressure relates to doctors’ assessments and final treatment decisions. The dataset includes 10 patients and contains information on visit frequency, blood pressure, doctor evaluations, and final care decisions. Using R, I created boxplots and a histogram to visualize patterns in the data. Methods I entered the dataset into R and converted the doctor assessments into numeric values. I then created: A basic boxplot of blood pressure Side-by-side boxplots comparing blood pressure with doctor ratings A histogram showing the overall distribution of blood pressure I also calculated summary statistics to support my interpretation. Results Boxplots The boxplots compare blood pressure with: First doctor rating (good vs bad) Second doctor assessment (low vs high) Final decision (low vs high) Histogram The histogram shows the overall distribution of blood pressure values. Di...

Creating and Analyzing Data Frames in R

Image
Intro In Module 3, I worked with data frames in R to organize and analyze polling data from a fictional 2016 presidential election dataset. The purpose of this exercise was to practice creating vectors, combining them into a data frame, and performing basic comparisons across variables using R. The dataset consists of three variables: Name – the candidate’s name ABC – polling results from the ABC source CBS – polling results from the CBS source Each row in the data frame represents one candidate, and each column represents a variable. This structure makes it easy to compare values across different polling sources.   Results and Observations After creating the data frame, I compared the results from ABC and CBS. Some candidates showed higher support in CBS polls, while others performed better in ABC polls. This highlights how different polling sources can produce varying results even when measuring the same data. I also added calculated columns to examine the difference...