MATH 734

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/33

encourage image

There's no tags or description

Looks like no tags are added yet.

34 Terms

1
New cards

What does Is() do?

Shows what has been defined in the environment

2
New cards

What is the output of the following code —> sum(c(TRUE,TRUE,FALSE,TRUE))

3 because a logic value is 1 for TRUE and 0 for FALSE

3
New cards

What is the output of the code c(1,10,100) * 1.5?

1.5 15.0 150.0

4
New cards

Given x ← c(a = 10, b = 20, c = 30)
x1 ← x[c(2,3)]
Are x[2] and x1[2] the same? And are x[‘b’] and x1[‘b’] the same? Briefly explain why or why not

  1. x[2] and x1[2] are not the same because x[2] refers to b 20 and x1[2] refers to c 30, since the second position of x1 is the third position of x

  2. x[‘b’] and x1[‘b’] are the same because they refer to names over position and since both x and x1 have ‘b’, they both output b = 20


5
New cards

What is the difference between identical() and all.equal()

  1. Identical() asks if these two objects are the exact same, down to how they look

    1. If you had 0.5-0.3 and 0.3-0.1, it would produce FALSE because they are not the same despite both equaling 0.2

  2. all.equal() asks if these values are equal, so in the previous example, it would be TRUE because both statements equate to 0.2


6
New cards

TRUE or FALSE
Run the code xx <- c(a=1, b=2)

Object xx does not have an attribute "names", because it does not use function attr() to add this attribute

FALSE because the names a and b auto make a names attribute for xx even if you didn’t use attr()

7
New cards

What does “rep” do?

rep Replicates the elements in a vector, it works like this

rep( value(s), x amount of times)

So rep(1,5) = 1 1 1 1 1 and

rep(c(1,2,3),4) = 1 2 3 1 2 3 1 2 3 1 2 3

8
New cards

What happens if you rep(c(1,2,3), c(2,1,4)

1 1 2 3 3 3 3
The number in each vector comes out as the amount on the other vector, so since it’s 2 in the first vector, it’s going to be 2 1s

9
New cards

What does “seq” do

seq makes a sequence of equally spaced numbers on a linear scale

so seq(1,15,2) works like (start, end, slope). This comes out as

1 3 5 7 9 11 13 15

10
New cards

How to use if and else together

Start with the if

if (x > 0.5) {

Then use a curly bracket to group the expression

cat(“head\n)

y ← 1

Then use else

} Else {

cat(“tail\n”)

y ← 0

}

11
New cards

Logical Conditions

FALSE || TRUE = TRUE

NA || TRUE = TRUE

FALSE | TRUE = TRUE


FALSE && TRUE = FALSE

NA && TRUE = NA


T || F || F = TRUE

12
New cards

How to bind a name to a function and use it

Do name ← function(x)

Then put in your function > sqrt(mean(x²))

13
New cards

What does body() do for a function

Shows what the body formula for the function is

14
New cards

What does formals() do for a function

Shows what the parameters are for the function (x,p)

15
New cards

What does return() do for a function

It returns a value from a function,

16
New cards

What happens if you don’t specify the input for a return function

It uses the default value

17
New cards

Decomposition

Breaking down a complex problem or system into smaller more manageable parts

18
New cards

Abstraction

Focusing on the important info only, ignoring irrelevant detail

19
New cards

Algorithms

Developing a step-by-step solution to the problem, or the rules to follow to solve the problem

20
New cards

What does prop.trim do

Removes all outliers and trims the same proportions on both sides

21
New cards

What does stopifnot() do

It’s a function that will stop any input if stopifnot() is NOT true

22
New cards

What does test_that do?

Groups a few checks and gives them a name. Works when something breaks which will spew out a sentence

23
New cards

What does expect_equal do?

Compares with a numerical tolerance, not tripping over the last decimal place

24
New cards

What does expect_error and expect_warning do

Checks a bad input and refuses it

25
New cards

What does Map do?

Map calls a function on each element of a sequence in order to transform: their individual components (sqrt,round), or the corresponding elements of many sequences

Useful in replacing loops

26
New cards

What does Reduce do?

Reduce applies a binary operation to combine consecutive elements in a sequence, e.g., to generate the aggregates

27
New cards

What does Filter do?

Creates a subset of a sequence that is comprised of elements that enjoy a given property

28
New cards

What does Find do?

Locates the first element that fufills some logical condition

29
New cards

What does lobstr::ast() do?

Displays the underlying tree structure

Like this

## █─f 	
## ├─a 
## └─"b"


30
New cards

How to add x,y and a title to a ggplot

Using the ggplot() function, you can add points with geom_point(), setthe x and y aesthetics with aes(x,y) and use the labs(title, x, y) to add labels to the plot

31
New cards

Acceptance-rejection sampling method transform the samples simulated from the working distribution and then accept them

TRUE

32
New cards

What is true of acceptance-rejection sampling

It needs the target density only up to a constant

The proposal must have heavier tails than the target

The accepted values are exact draws from the target

33
New cards

Using acceptance-rejection with utility distribution, how many samples do you need

c * n samples, where c = some constant and n is the amount of samples

34
New cards