QMST 3339 Midterm

.docx

School

Texas State University *

*We aren’t endorsed by this school

Course

3339

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

3

Uploaded by knausecaleb

Report
data : The data elements that will fill the matrix, usually given as a vector. R will fill the matrix column-wise by default. nrow : The number of rows in the matrix. ncol : The number of columns in the matrix. byrow : A logical value indicating whether the matrix should be filled by rows ( TRUE ) or by columns ( FALSE , which is the default). dimnames : An optional argument that allows you to provide names for rows and columns. matrix (data, nrow, ncol, byrow, dimnames) Using the eq() function: The seq() function generates sequences of numbers. Using the rep() function: The rep() function replicates elements in a vector. One can create patterns of categories that are usefulin designs of experiments. To free up memory, you can remove a variable using the rm() function: The elements of a logical vector can have the values TRUE , FALSE , and NA (for “not available”). The logical operators are <, <=, >, >=, == for exact equality and != for inequality. & = “and” | = “or” You can use a numeric vector of indexes to access multiple elements at once, e.g.  my_vector[c(2, 4, 6)] . selected_values = my_vector[my_vector > 0] Now we can use the index to extract those elements in the positions that contain values # use the index to extract from w y <- w[index] print(y) For matrices, use row and column indexes separated by a comma inside square brackets, e.g.  my_matrix[2, 3] retrieves the element in the second row and third column. [row,column] You can use my_matrix[2, ] to access the entire second row and my_matrix[, 3] for the third column. Similar to vectors, logical conditions can be applied to matrices for indexing, e.g.  subset_matrix = my_matrix[my_matrix > 10] . You can create a data frame from individual vectors using the data.frame() function, e.g. my_df <- data.frame(names, ages). Use colnames(my_df) to view or modify column names. You can access a column using the $ operator, e.g. my_df$names. Aggregate data using functions like aggregate() to compute summary statistics for subsets. aggregate(x, by, FUN, …, simplify = TRUE, drop = TRUE) aggregate(x = my_df$ages, by = list(my_df$sex), FUN = mean) # Shows the top 6 records # Shows the bottom 6 records tail(ws) head(ws) summary is a generic function used to produce result summaries of the results of various model fitting functions.
summary(object, ..., digits, quantile.type = 7) # there are about 9 different ways of computing quantiles summary(object = ws,digits = 4, quantile.type = 2) mean(ws$Gas) median(ws$Gas) var(ws$Gas) (variance) sd(ws$Gas) (standard deviation) # Coefficient of variation sd(ws$Gas)/mean(ws$Gas) # Returns Tukey's five number summary (minimum, lower-hinge, median, upper-hinge, maximum) for the data. fivenum(x = ws$Gas) # Categorize age to identify minors titanic$minor <- ifelse(titanic$age < 18, "Minor", "Adult") lm(sales~TV, data = dat) <- linear model function gives co-efficients for both variables Uses least squares approach linear regression # discard the first variable summary(dat[,-1]) For validations, we perform a data split: train versus test 80% training and 20% testing is common set.seed(111) index <- sample(x = 1:dim(dat)[1],size = ceiling(0.80*dim(dat)[1])) # sample observations training_set <- dat[index,] # select observations testing_set <- dat[-index,] The residual standard error is the standard deviation of the observed residuals. summary(model1)$sigma sqrt(sum(model1$residuals^2)/(model1$df.residual))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help