Posts

Showing posts from February, 2024

Module #7 Assignment

 For this assignment, I used the popular mtcars dataset for my analysis. My code is as follows: data("mtcars") head(mtcars) list(mtcars) #we can create generic functions for mtcars such as functions to find the  #mean or a function to create plots such as bar or scatter plots. #S3 method class(mtcars) summary.mtcars <- function(object, ...) {   summary(object) } summary(mtcars) #S3 methods can be applied #s4 method setClass("mtcarsClass", contains = "data.frame") mtcars_s4 <- new("mtcarsClass", mtcars) mtcars_s4 #S4 methods can be applied How do you tell what OO system (S3 vs. S4) an object is associated with? You can use the functions isS3method() and is4() How do you determine the base type (like integer or list) of an object? You can use the class function What is a generic function? A function that behaves according to the class it is applied to. What are the main differences between S3 and S4? S4 is more complex and structured than S3....

Module #6

 For this assignment, I created four matrices based on the given A and B data. Here are my results: > A <- matrix(c(2, 0, 1, 3), ncol = 2) > B <- matrix(c(5, 2, 4, -1), ncol = 2) > Matrix_one <- A + B > Matrix_one [,1] [,2] [1,] 7 5 [2,] 2 2 > Matrix_two <- A - B > Matrix_two [,1] [,2] [1,] -3 -3 [2,] -2 4 > diag_matrix <- diag(c(4, 1, 2, 3)) > diag_matrix [,1] [,2] [,3] [,4] [1,] 4 0 0 0 [2,] 0 1 0 0 [3,] 0 0 2 0 [4,] 0 0 0 3 > final_matrix <- diag(3, 5) > final_matrix [,1] [,2] [,3] [,4] [,5] [1,] 3 0 0 0 0 [2,] 0 3 0 0 0 [3,] 0 0 3 0 0 [4,] 0 0 0 3 0 [5,] 0 0 0 0 3 >

Module #5

 2/11/24 For this assignment, I defined the matrices A and B, then attempted to find their inverse and determinant using the solve() and det() functions. I got these errors, which I believe is because is singular and therefore not invertible.  > A <- matrix(1:100, nrow=10) > B <- matrix(1:1000, nrow=10) > solve(A) Error in solve.default(A) : Lapack routine dgesv: system is exactly singular: U[6,6] = 0 > det(A) [1] 0 > A <- matrix(1:100, nrow=10) > B <- matrix(1:1000, nrow=10) > solve(A) Error in solve.default(A) : Lapack routine dgesv: system is exactly singular: U[6,6] = 0 > det(A) [1] 0 > solve(B) Error in solve.default(B) : 'a' (10 x 100) must be square > det(B) Error in determinant.matrix(x, logarithm = TRUE, ...) : 'x' must be a square matrix > A <- matrix(1:100, nrow=10) > B <- matrix(1:1000, nrow=10) > solve(A) Error in solve.default(A) : Lapack routine dgesv: system is exactly singular: U[6,6] ...

Module #4

Image
First, I entered the data and created a data frame:   Freq <- c(0.6, 0.3, 0.4, 0.4, 0.2, 0.6, 0.3, 0.4, 0.9, 0.2) bloodp <- c(103, 87, 32, 42, 59, 109, 78, 205, 135, 176) first <- c("bad", "bad", "bad", "bad", "good", "good", "good", "good", NA, "bad") second <- c("low", "low", "high", "high", "low", "high", "high", "high", "high", "high") finaldecision <- c("low", "high", "low", "high", "low", "high", "low", "high", "high", "high")   first <- factor(first, levels = c("bad", "good")) second <- factor(second, levels = c("low", "high")) finaldecision <- factor(finaldecision, levels = c("low", "high"))...