QMST 3339 Midterm
.docx
keyboard_arrow_up
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
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
Related Questions
You are working for a company that developed a new drug which increases HDL cholesterol (the good
cholesterol). A variety of dosages were given to participants during a trial, and the increases of HDL cholesterol
were measured. This information is summarized in the following plot:
Dosage vs Increase
80
70
60
50
40
30
20
10
15
x - dosage in mg
10
20
25
30
Each point (x, y) in the above plot represents a participant who was given a dosage of æ mg and had an HDL
increase of y mg/dL. This information is stored in the 2d numpy array trial_data. The r-values are stored in
the first row of trial_data (i.e. trial_data[@]) and the y-values are stored in the second row of trial_data (i.e.
trial_data[1]).
You are now working with a physician to determine the right dosage for one of her patients.
1) In order to help your client, first find a vector B =
[B1]
such that y(x) = B1 + Bza is the least squares line
[B2]
for the above data. Store the vector B as a 1D-numpy array in beta.
2) The physician…
arrow_forward
Create method Determine Results: The method will receive a two dimensional array which contains the values of each tic tac toe location The method will determine the results The method will return X if X wins, O if O wins, T if it is a tie, or ? if it is undetermined
arrow_forward
switch_player(): we will allow the players to choose their own names, but for our purposes, it is easier to think of them as number (0 and 1, for indexing purposes). We will display their names to them on the screen, but in the background, we will keep track of them based on their number. This function should take 1 argument, an integer (either 0 or 1) representing the player and should return the opposite integer (1 if 0 is entered and 0 if 1 is entered). This is a simple function, but it will make our code cleaner later. Use your constants!
Using Thonny
arrow_forward
Programming Language: C++
Create a structure Student and ask the user how many students. Create an array which will save the number of students in the input. Ask for the data of the first and last student and display them. Do not copy paste other codes from other site and use comments to understand it clearly.
arrow_forward
Comment block: Set up comments using the standard format in a <# and #> container, which should contain a synopsis, description, and at least one example which shows how to run the script.
Set up an array: Put values in the array $ComputerNames, containing the names of two computers: DC1 and W10-CLIENT.
Prompt for user's name: Use the text Please enter your first name, store the value the user will provide in a variable named $FirstName, and write out the text Hello followed by a space, followed by the name entered.
Prompt for report type, and store value provided: Ask the user to enter AD if the information on Active Directory Users is required, and WMI for Windows Machine Instrumentation. Store the answer provided in variable $ReportType
Confirm report selection: If an Active Directory report was requested, on a new line print the message "A list of all AD users was requested for computers " followed by the contents of the $ComputerNames array. If a Windows Machine…
arrow_forward
Computer Science
Javascript
populateSelectMenu function
The function populateSelectMenu should exist.
The function populateSelectMenu should return undefined if it does not receive users data.
The function populateSelectMenu selects and returns the select menu.
The function populateSelectMenu receives the option elements from createSelectOptions and appends them to the select element.
arrow_forward
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. The flowchart must include a call symbol, at the beginning, to redirect the input to the external data file.
create a solution algorithm using pseudocode
create a flowchart using RAPTOR
arrow_forward
Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. Design a flowchart and psuedocode Pendant Publishing.
arrow_forward
く
Interval intersection
[ ] # @title Interval intersection
def interval_and(self, other):
"""Intersection%; returns an interval, or None."""
if other.x0 > self.x1:
return None
x0 = max(self.x0, other.x0)
x1 = min(self.x1, other.x1)
return Interval(x0, x1)
Interval. _and____ = interval_and
# Tests 10 points.
Interval(6, 10)
assert Interval(3, 10) & Interval(6, 20)
assert Interval(3, 4) & Interval(5, 6) is None
[↑]
AttributeError
Traceback (most recent call last)
in ()
1 # Tests 10 points.
2
3 assert Interval (3, 10) & Interval(6, 20) ==
Interval (6, 10)
4 assert Interval (3, 4) & Interval(5, 6) is None
in interval_equality(self, other)
return False
7
8
9
return self.start == other.start and self.end == other.end
10
11
arrow_forward
Javascript
createSelectOptions function
The function createSelectOptions should exist.
The function createSelectOptions returns undefined if no data parameter is provided.
The function createSelectOptions returns an array.
The function createSelectOptions returns an array with the correct length.
The function createSelectOptions returns an array of option elements.
The function createSelectOptions assigns the related user id to the value attribute of the options elements.
The function createSelectOptions assigns the related user name to the textContent attribute of the options elements.
createSelectOptionsa. Test users JSON data available here: https://jsonplaceholder.typicode.com/usersb. For testing (not in function) you may want to define users with the test data.c. Receives users JSON data as a parameterd. Returns undefined if no parameter receivede. Loops through the users dataf. Creates an option element for each user with document.createElement()g. Assigns the…
arrow_forward
Javascript
createSelectOptions function
The function createSelectOptions should exist.
The function createSelectOptions returns undefined if no data parameter is provided.
The function createSelectOptions returns an array.
The function createSelectOptions returns an array with the correct length.
The function createSelectOptions returns an array of option elements.
The function createSelectOptions assigns the related user id to the value attribute of the options elements.
The function createSelectOptions assigns the related user name to the textContent attribute of the options elements.
createSelectOptionsa. Test users JSON data available here: https://jsonplaceholder.typicode.com/usersb. For testing (not in function) you may want to define users with the test data.c. Receives users JSON data as a parameterd. Returns undefined if no parameter receivede. Loops through the users dataf. Creates an option element for each user with document.createElement()g. Assigns the…
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Related Questions
- You are working for a company that developed a new drug which increases HDL cholesterol (the good cholesterol). A variety of dosages were given to participants during a trial, and the increases of HDL cholesterol were measured. This information is summarized in the following plot: Dosage vs Increase 80 70 60 50 40 30 20 10 15 x - dosage in mg 10 20 25 30 Each point (x, y) in the above plot represents a participant who was given a dosage of æ mg and had an HDL increase of y mg/dL. This information is stored in the 2d numpy array trial_data. The r-values are stored in the first row of trial_data (i.e. trial_data[@]) and the y-values are stored in the second row of trial_data (i.e. trial_data[1]). You are now working with a physician to determine the right dosage for one of her patients. 1) In order to help your client, first find a vector B = [B1] such that y(x) = B1 + Bza is the least squares line [B2] for the above data. Store the vector B as a 1D-numpy array in beta. 2) The physician…arrow_forwardCreate method Determine Results: The method will receive a two dimensional array which contains the values of each tic tac toe location The method will determine the results The method will return X if X wins, O if O wins, T if it is a tie, or ? if it is undeterminedarrow_forwardswitch_player(): we will allow the players to choose their own names, but for our purposes, it is easier to think of them as number (0 and 1, for indexing purposes). We will display their names to them on the screen, but in the background, we will keep track of them based on their number. This function should take 1 argument, an integer (either 0 or 1) representing the player and should return the opposite integer (1 if 0 is entered and 0 if 1 is entered). This is a simple function, but it will make our code cleaner later. Use your constants! Using Thonnyarrow_forward
- Programming Language: C++ Create a structure Student and ask the user how many students. Create an array which will save the number of students in the input. Ask for the data of the first and last student and display them. Do not copy paste other codes from other site and use comments to understand it clearly.arrow_forwardComment block: Set up comments using the standard format in a <# and #> container, which should contain a synopsis, description, and at least one example which shows how to run the script. Set up an array: Put values in the array $ComputerNames, containing the names of two computers: DC1 and W10-CLIENT. Prompt for user's name: Use the text Please enter your first name, store the value the user will provide in a variable named $FirstName, and write out the text Hello followed by a space, followed by the name entered. Prompt for report type, and store value provided: Ask the user to enter AD if the information on Active Directory Users is required, and WMI for Windows Machine Instrumentation. Store the answer provided in variable $ReportType Confirm report selection: If an Active Directory report was requested, on a new line print the message "A list of all AD users was requested for computers " followed by the contents of the $ComputerNames array. If a Windows Machine…arrow_forwardComputer Science Javascript populateSelectMenu function The function populateSelectMenu should exist. The function populateSelectMenu should return undefined if it does not receive users data. The function populateSelectMenu selects and returns the select menu. The function populateSelectMenu receives the option elements from createSelectOptions and appends them to the select element.arrow_forward
- Pendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. The flowchart must include a call symbol, at the beginning, to redirect the input to the external data file. create a solution algorithm using pseudocode create a flowchart using RAPTORarrow_forwardPendant Publishing edits multi-volume manuscripts for many authors. For each volume, they want a label that contains the author’s name, the title of the work, and a volume number in the form Volume 9 of 9. For example, a set of three volumes requires three labels: Volume 1 of 3, Volume 2 of 3, and Volume 3 of 3. Design an application that reads records that contain an author’s name, the title of the work, and the number of volumes. The application must read the records until eof is encountered and produce enough labels for each work. Design a flowchart and psuedocode Pendant Publishing.arrow_forwardく Interval intersection [ ] # @title Interval intersection def interval_and(self, other): """Intersection%; returns an interval, or None.""" if other.x0 > self.x1: return None x0 = max(self.x0, other.x0) x1 = min(self.x1, other.x1) return Interval(x0, x1) Interval. _and____ = interval_and # Tests 10 points. Interval(6, 10) assert Interval(3, 10) & Interval(6, 20) assert Interval(3, 4) & Interval(5, 6) is None [↑] AttributeError Traceback (most recent call last) in () 1 # Tests 10 points. 2 3 assert Interval (3, 10) & Interval(6, 20) == Interval (6, 10) 4 assert Interval (3, 4) & Interval(5, 6) is None in interval_equality(self, other) return False 7 8 9 return self.start == other.start and self.end == other.end 10 11arrow_forward
- Javascript createSelectOptions function The function createSelectOptions should exist. The function createSelectOptions returns undefined if no data parameter is provided. The function createSelectOptions returns an array. The function createSelectOptions returns an array with the correct length. The function createSelectOptions returns an array of option elements. The function createSelectOptions assigns the related user id to the value attribute of the options elements. The function createSelectOptions assigns the related user name to the textContent attribute of the options elements. createSelectOptionsa. Test users JSON data available here: https://jsonplaceholder.typicode.com/usersb. For testing (not in function) you may want to define users with the test data.c. Receives users JSON data as a parameterd. Returns undefined if no parameter receivede. Loops through the users dataf. Creates an option element for each user with document.createElement()g. Assigns the…arrow_forwardJavascript createSelectOptions function The function createSelectOptions should exist. The function createSelectOptions returns undefined if no data parameter is provided. The function createSelectOptions returns an array. The function createSelectOptions returns an array with the correct length. The function createSelectOptions returns an array of option elements. The function createSelectOptions assigns the related user id to the value attribute of the options elements. The function createSelectOptions assigns the related user name to the textContent attribute of the options elements. createSelectOptionsa. Test users JSON data available here: https://jsonplaceholder.typicode.com/usersb. For testing (not in function) you may want to define users with the test data.c. Receives users JSON data as a parameterd. Returns undefined if no parameter receivede. Loops through the users dataf. Creates an option element for each user with document.createElement()g. Assigns the…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning