1  Intro to Optimization

📜 Economics is the best! 📜

Listing 1.1: Addition within R
1 + 1                                    

1.1 Optimization

  1. We can write inline equations like \(E = mc^2\) or display equations:

\[ \frac{\partial u}{\partial t} = \alpha \frac{\partial^2 u}{\partial x^2} \]

The quadratic formula is given by:

\[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]

1.2 R Plot Example

# Generate sample data
set.seed(42)
x <- seq(1, 10, length.out = 50)
y <- 2 * x + rnorm(50, mean = 0, sd = 2)

# Create plot
plot(x, y, 
     main = "Linear Relationship",
     xlab = "X Variable",
     ylab = "Y Variable",
     pch = 19,
     col = "steelblue")

# Add regression line
abline(lm(y ~ x), col = "red", lwd = 2)
Figure 1.1: A simple R scatter plot with regression line

For more complex bits of analysis, hidden annotations are available (the reader can further access notes/assistance by hovering over the circled numbers):

library(psych)
data(bfi)

bfi$jibberish <- rowMeans(bfi[1:10], na.rm=TRUE)
bfi$gobbleyjook <- rowMeans(bfi[11:20], na.rm=TRUE)
1
The psych package contains example data that we can access.
2
This gives us access to the bfi dataset that contains personality item responses.
3
We make 2 scale scores, jibberish and gobbleyjook. The $ notation indicates that these scale scores will be appended to the bfi dataframe.

The entire code block can also be hidden unless asked-for. These features permit reviewers/collaborators of different need or curiosity to access source code on an as-needed basis:

Code
library(psych)
data(bfi)

bfi$jibberish <- rowMeans(bfi[1:10], na.rm=TRUE)
bfi$gobbleyjook <- rowMeans(bfi[11:20], na.rm=TRUE)
1
The psych package contains example data that we can access.
2
This gives us access to the bfi dataset that contains personality item responses.
3
We make 2 scale scores, jibberish and gobbleyjook. The $ notation indicates that these scale scores will be appended to the bfi dataframe.

1.3 Data Summaries

Summaries of your analyses are typically the most important (to external review) aspect of your work. These are the illustrations of your story. The primary principles of analyses within a literate programming framework are:

  1. Preserve the source data
  2. Document all manipulations

Below you can find a few data presentation enhancements that are enabled via literate programming platforms.

1.3.1 Data vizualizations

Figure 1.2 demonstrates lightbox capabilities for images embedded within literate programming reports, whereby “clicking” isolates the image for closer inspection. This is useful for images that contain fine detail, user devices that may not display optimally, drawing focus to specific data features, and increasing accessibility for visually impaired viewers.

Figure 1.3 highlights standard interactive components for graphical representations of data. These interactive components are fully accessible within the source document/presentation.

Figure 1.3: Example interactive plot

Figure 1.4 is another example of interactivity - a map such as this can help reinforce viewer concepts such as representativeness within normative samples (e.g., where the data “came from” and who the data represents). The audience can get a sense of geographic representation by “zooming out” or “zooming in” and verifying that only North America is represented within this dataset.

Figure 1.4: Example normative representation by geographic location.

1.3.2 Informational Tutorials

Video 1.1 shows another example - videos can be pulled from external sites (like this tutorial on parameterized reporting within Quarto) or can present locally produced video files.

Video 1.1: Parameterized reports

1.4 Interactive JSXGraph Examples

1.4.1 Method 1: Including External HTML File

Students can drag points to see how the slope changes:

1.4.2 Method 2: Inline HTML with Sliders

Adjust the sliders to modify the parabola \(f(x) = ax^2 + b\):

1.4.3 Method 3: Inline Raw HTML

1.5 Observable JS Examples

1.5.1 Method 1: Embedded Observable module (runtime)

Below is an embedded Observable notebook using the Observable runtime. This imports the runtime and an example notebook module from Observable's API and renders it inline.

1.5.2 Method 2: Iframe fallback

If the module import is blocked or unavailable, this iframe provides a simple fallback to view the same notebook directly from Observable.