@@ -223,17 +223,16 @@ while the inset panel (left) magnifies the region near zero $[-1, 1]$.
223223library(grasps) ## for penalty computation
224224library(ggplot2) ## for visualization
225225
226- omegas <- seq(-4, 4, by = 0.01)
227226penalties <- c("atan", "exp", "lasso", "lq", "lsp", "mcp", "scad")
228227
229- df <- grasps::pen(omegas , penalties, lambda = 1)
230- plot(df , xlim = c(-1, 1), ylim = c(0, 1), zoom.size = 1) +
228+ pen_df <- grasps::pen(seq(-4, 4, by = 0.01) , penalties, lambda = 1)
229+ plot(pen_df , xlim = c(-1, 1), ylim = c(0, 1), zoom.size = 1) +
231230 guides(color = guide_legend(nrow = 2, byrow = TRUE))
232231```
233232
234233
235234``` {r echo=FALSE, fig.show='hide'}
236- plot <- plot(df , xlim = c(-1, 1), ylim = c(0, 1), zoom.size = 1) +
235+ plot <- plot(pen_df , xlim = c(-1, 1), ylim = c(0, 1), zoom.size = 1) +
237236 guides(color = guide_legend(nrow = 2, byrow = TRUE))
238237```
239238
@@ -257,28 +256,26 @@ $\vert\omega\vert$ increases, reflecting their tendency to shrink small
257256$\vert\omega\vert$ strongly while exerting little to no shrinkage on large ones.
258257
259258
260- ::: {#fig-deriv}
261- ``` {r fig.cap="Figure 2: Illustrative penalty derivatives."}
262- df <- grasps::deriv(omegas, penalties, lambda = 1)
263- ggplot(df, aes(x = omega, y = value, color = penalty)) +
264- geom_line() +
265- scale_x_continuous(limits = c(0, 4)) +
259+ ``` {r fig.show='hide'}
260+ deriv_df <- grasps::deriv(seq(0, 4, by = 0.01), penalties, lambda = 1)
261+ plot(deriv_df) +
262+ scale_y_continuous(limits = c(0, 1.5)) +
263+ guides(color = guide_legend(nrow = 2, byrow = TRUE))
264+ ```
265+
266+
267+ ``` {r echo=FALSE, fig.show='hide'}
268+ plot <- plot(deriv_df) +
266269 scale_y_continuous(limits = c(0, 1.5)) +
267- xlab(expression(italic(omega))) +
268- ylab(expression("Derivative Function" ~ italic(p) * "'(" * italic(omega) * ")")) +
269- scale_color_discrete(name = "Penalty Type",
270- labels = c(expression(atan ~ "(" * gamma == 0.005 * ")"),
271- expression(exp ~ "(" * gamma == 0.01 * ")"),
272- "lasso",
273- expression(lq ~ "(" * gamma == 0.5 * ")"),
274- expression(lsp ~ "(" * gamma == 0.1 * ")"),
275- expression(mcp ~ "(" * gamma == 3 * ")"),
276- expression(scad ~ "(" * gamma == 3.7 * ")"))) +
277- guides(color = guide_legend(nrow = 2, byrow = TRUE)) +
278- theme_bw() +
279- theme(aspect.ratio = 1,
280- legend.position = "bottom")
270+ guides(color = guide_legend(nrow = 2, byrow = TRUE))
271+ ```
272+
273+
274+ ::: {#fig-deriv}
275+ ``` {r echo=FALSE}
276+ print(plot)
281277```
278+ Illustrative penalty derivatives.
282279:::
283280
284281
0 commit comments