@@ -55,7 +55,9 @@ watermark: false
55
55
footer_contents : " Rcpp Vignette"
56
56
57
57
# Produce a pinp document
58
- output : pinp::pinp
58
+ output :
59
+ pinp::pinp :
60
+ collapse : true
59
61
60
62
# Local additiona of a few definitions we use
61
63
header-includes : >
@@ -86,6 +88,7 @@ vignette: >
86
88
``` {r setup, include=FALSE}
87
89
knitr::opts_chunk$set(cache=TRUE)
88
90
library(Rcpp)
91
+ options("width"=50, digits=5)
89
92
```
90
93
91
94
193
196
As a first step, and chiefly to establish that the toolchain is set up correctly, consider
194
197
a minimal use case such as the following:
195
198
196
- ``` {r evalCpp, eval=FALSE }
199
+ ``` {r evalCpp}
197
200
library("Rcpp")
198
201
evalCpp("2 + 2")
199
202
```
@@ -225,6 +228,7 @@ isOddR <- function(num = 10L) {
225
228
result <- (num %% 2L == 1L)
226
229
return(result)
227
230
}
231
+ isOddR(42L)
228
232
```
229
233
230
234
The operator ` %% ` implements the $\bmod$ operation in \rlangns. For the default
@@ -259,7 +263,7 @@ that represents the \cpp code. Upon calling the `cppFunction()`, and similarly t
259
263
earlier example involving ` evalCpp() ` , the \cpp code is both _ compiled_ and _ linked_ , and
260
264
then _ imported_ into \rlang under the name of the function supplied (_ e.g._ here ` isOddCpp() ` ).
261
265
262
- ``` {r isOddRcpp, cache=TRUE, eval=FALSE }
266
+ ``` {r isOddRcpp}
263
267
library("Rcpp")
264
268
cppFunction("
265
269
bool isOddCpp(int num = 10) {
@@ -509,7 +513,7 @@ set.seed(123)
509
513
rnorm(3)
510
514
```
511
515
512
- # Translating Code from \rlang into \rcppns: A Bootstrapping Example
516
+ # Translating Code from \rlang into \rcppns: Bootstrap Example
513
517
514
518
Statistical inference relied primarily upon asymptotic theory until
515
519
\cite{Efron:1979: Bootstrap } proposed the bootstrap. Bootstrapping is known
@@ -564,7 +568,7 @@ make_boot_graph <- function(ds, actual, type, ylim){
564
568
abline(v = actual, col = "orange2", lwd = 2)
565
569
lines(density(ds))
566
570
}
567
- pdf("bootstrap.pdf", width=6.5, height=3.25)
571
+ pdf("figures/ bootstrap.pdf", width=6.5, height=3.25)
568
572
par(mfrow=c(1,2))
569
573
make_boot_graph(result_r[,1], 21, "Mean", c(0, 1.23))
570
574
make_boot_graph(result_r[,2], 10, "SD", c(0, 1.85))
@@ -573,7 +577,7 @@ dev.off()
573
577
574
578
\begin{figure* }
575
579
\begin{center}
576
- \includegraphics[ width=6.5in, height=3.25in] {bootstrap}
580
+ \includegraphics[ width=6.5in, height=3.25in] {figures/ bootstrap}
577
581
\caption{Results of the bootstrapping procedure for sample mean and variance.}
578
582
\label{fig: bootstrap-graphs }
579
583
\end{center}
@@ -809,13 +813,10 @@ Rcpp::List fastLm(const arma::mat& X,
809
813
const arma::colvec& y) {
810
814
// Dimension information
811
815
int n = X.n_rows, p = X.n_cols;
812
-
813
816
// Fit model y ~ X
814
817
arma::colvec coef = arma::solve(X, y);
815
-
816
818
// Compute the residuals
817
819
arma::colvec res = y - X*coef;
818
-
819
820
// Estimated variance of the random error
820
821
double s2 =
821
822
std::inner_product(res.begin(), res.end(),
0 commit comments