Posts

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"))...

Module #3

 1/28/2024 For this module I created a data frame based on the 2016 election results: election <- data.frame(   Name = c("Jeb", "Donald", "Ted", "Marco", "Carly", "Hillary", "Bernie"),   ABC_Poll_Results = c(4, 62, 51, 21, 2, 14, 15),   CBS_Poll_Results = c(12, 75, 43, 19, 1, 21, 19) ) These were my results: > print(election) Name ABC_Poll_Results CBS_Poll_Results 1 Jeb 4 12 2 Donald 62 75 3 Ted 51 43 4 Marco 21 19 5 Carly 2 1 6 Hillary 14 21 7 Bernie 15 19 Donald is the clear winner in both polls, scoring 62 and 75 respectively. Second comes Ted with 51 and 43. 

Module #2

3. Your assignment, evaluate the following function call  myMean . The data for this function called  assignment .  The myMean function successfully calculates the mean of the assignment2 vector. Sum divided by the length of the vector returns the mean.  assignment2 <- c(16, 18, 14, 22, 27, 17, 19, 17, 17, 22, 20, 22) myMean <- function(assignment2) {   return(sum(assignment2) / length(assignment2)) } myMean(assignment2) > myMean(assignment2) [1] 19.25

Module #1

 My GitHub repository:  elisah99/LIS4370 (github.com)