Maps in Data

Stat 251

2025-04-29

Logistics

Feedback

  • Graded: homework 11 (functions - really: lists)

  • Today: last edits for scripts

  • Thursday: submit your screencast

    adding timestamps as chapters

    no required attendance in class on Thursday (May 1)

Script

For each of the Things you defined, write out at least three paragraphs:

Make sure to:

  • include definitions (i.e. how do you measure strength)
  • give context (i.e. which variables are used)
  • tie ‘things’ in with the topics in the class

Functions and List

are the extension of vector calculus

(x <- sample(1:10, 15, replace = TRUE))
 [1]  8  8  5  5  6  2  4  5  7  6  1 10 10  4  2
(y <- sample(1:10, 15, replace = TRUE))
 [1]  8  6  8  2 10  9  7  9  7  2  2  4  2  1  1

Add the first element in x to the first element in y:

x[1] + y[1]
[1] 16

Now do that for all elements in x and y:

x + y
 [1] 16 14 13  7 16 11 11 14 14  8  3 14 12  5  3
1:length(x) |> lapply(FUN = function(i) x[i] + y[i]) |> unlist()
 [1] 16 14 13  7 16 11 11 14 14  8  3 14 12  5  3
sum_xy = map(lambda i: r.x[i]+r.y[i], range(1,len(r.x)))
list(sum_xy)
[14, 13, 7, 16, 11, 11, 14, 14, 8, 3, 14, 12, 5, 3]

Your Turn: Graphs of functions

Plot the graph of the function for \(\alpha = \beta = 1/2\) on the interval [0,1]:

\[ f(x) = \frac{1}{B(\alpha, \beta)} x^{\alpha -1} (1 - x)^{\beta - 1} \] \(B(\alpha, \beta)\) is the beta function - a generalization of the (inverse) binomial coefficient. Implemented as beta(a, b) in R, in python use math.gamma and the relationship to the Gamma function \(\Gamma\):

\[ B(a, b) = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a + b)} \]

Your Turn: Multiple Graphs

Now make \(\alpha\) a vector alpha and plot graphs for values of \(\alpha \in \{ 0.5, 0.6, ..., 1.2\}\)

… can you vectorize \(\beta\) similarly?

Homework 12