Posts

Showing posts from February, 2026

Assignment #6

Image
In this module I practiced basic matrix math in R. I created two matrices, A and B, using the matrix function. Since R fills matrices by column, I checked how they looked first and then did the operations. To find A + B and A − B, I just used A + B and A - B in R. Matrix addition and subtraction are done element by element, so each number lines up with the same position in the other matrix. R printed the results correctly for both operations. Next, I used the diag() function to build a 4x4 diagonal matrix with the values 4, 1, 2, and 3 on the diagonal. A diagonal matrix has zeros everywhere except the diagonal from top left to bottom right. I created it with diag(c(4,1,2,3), 4, 4) and the output matched what the question asked for. For the last question, I had to generate a specific 5x5 matrix. I started with a diagonal matrix of 3s using diag(3, 5) . Then I edited the first column to be 3, 2, 2, 2, 2 and changed the first row to 3, 1, 1, 1, 1. After those small edits, the matrix...

Assignment #5

Image
 For Module #5, I practiced matrix operations in R and checked whether two matrices could be inverted. First, I created the matrices using the assignment instructions: A <- matrix(1:100, nrow = 10) and B <- matrix(1:1000, nrow = 10) . I used dim(A) and dim(B) to confirm their sizes. Matrix A is a 10×10 square matrix, while matrix B is a 10×100 matrix, which means B is not square. Next, I calculated the determinant of A using det(A) . The determinant came out to be 0 , which tells me A is singular . A singular matrix does not have an inverse, so when I attempted solve(A) R returned an error (I used tryCatch() to capture the error message without stopping my code). I also attempted solve(B) , but that also produced an error because non-square matrices do not have inverses . So the results were expected: A cannot be inverted because its determinant is 0, and B cannot be inverted because it is not square. After checking inverses, I explored additional matrix operations to ...

Assignment #4

Image
 This assignment used a dataset from a local hospital that recorded information on ten patients. The variables included frequency of hospital visits in the past year, blood pressure measurements, the first doctor’s assessment, the second doctor’s assessment, and the final emergency decision. The data was entered into R as vectors and combined into a data frame. A boxplot and histogram were created to visualize the blood pressure values for the patients. The histogram showed that most patients had moderate blood pressure readings, while a few had very high values such as 176 and 205. The boxplot highlighted these extreme readings as outliers compared to the rest of the group. The majority of patients fell within a lower to mid-range of blood pressure, but the spread of values showed that there was significant variation across the ten patients. Patients with higher blood pressure readings were more likely to receive a high final decision for immediate care. When both doctors rated ...

Assignment #3

Image
 In this assignment, I created a fictional dataset in R to represent polling results from two different news sources, ABC and CBS, during the 2016 presidential election. The dataset consisted of a vector of candidate names and two numeric vectors representing the poll results from each source. Although the data does not reflect the real election, the purpose of the assignment was to practice working with vectors and organizing them into a data frame, as discussed in Chapter 5 of The Art of R Programming . After creating the vectors, I combined them into a data frame so the information could be viewed in a tabular format. This made it easier to compare the polling results across candidates and sources. I then added a new column to the data frame that calculated the difference between the CBS and ABC polls (CBS − ABC). The results showed that several candidates, including Jeb, Donald, Hillary, and Bernie, had higher values in the CBS poll, while others such as Ted, Marco, and Carly ...