25 : r(r), dr(dr), ic(ic) {
27 arma::arma_rng::set_seed_random();
31 for (
unsigned i=0; i <
n; i++)
inp(i) = i;
32 this->
ord = arma::conv_to<arma::uvec>::from(inp);
35 this->
b = arma::vec();
39 unsigned p = inp.n_cols;
40 arma::umat
ord(inp.n_rows, p);
41 this->inp = arma::mat(inp.n_rows, p);
42 for (
unsigned j=0; j < p; j++) {
43 arma::vec inpj = inp.col(j);
44 ord.col(j) = arma::stable_sort_index(inpj);
45 this->inp.col(j) = inpj.elem(ord.col(j));
48 if (p == 1 && b.n_elem==0) {
49 eta = arma::cumsum(
dr.rows(ord), 0);
53 arma::vec newb = arma::vec(p);
54 for (
unsigned i=0; i<p; i++) newb(i) =
b(0);
67 return Rcpp::as<arma::vec>(Rcpp::rnorm(
n));
69 return arma::randn<arma::vec>(
n);
90 arma::mat res(
n,
inp.n_cols);
91 double scale = std::sqrt(static_cast<double>(
n));
92 for (
unsigned j=0; j <
inp.n_cols; j++) {
94 arma::vec ro =
r.elem(
ord.col(j));
95 arma::vec rj = arma::cumsum(ro);
98 for (
unsigned i=0; i < ro.n_elem; i++) {
100 while (
inp(pos) >=
inp(i)-
b(j)) pos++;
101 res(i,j) = (rj(i) - rj(pos)) / scale;
104 arma::vec rj = arma::cumsum(
r.elem(
ord.col(j))) / scale;
118 arma::vec g =
rnorm();
120 unsigned p =
ord.n_cols;
121 if (!idx.is_empty()) {
125 for (
unsigned i=0; i < p; i++) {
126 arma::uvec curord =
ord.col(i);
127 arma::vec w1 = arma::cumsum(
r.elem(curord)%g);
130 eta = arma::cumsum(
dr.rows(curord), 0);
132 arma::rowvec B(
ic.n_cols);
133 for (
unsigned j=0; j <
ic.n_cols; j++) {
134 arma::vec tmp =
ic.col(j);
135 B(j) = sum(tmp.elem(curord)%g);
138 if (!idx.is_empty()) {
139 w1 = w1.elem(idx.col(i));
140 for (
unsigned j=0; j < N; j++) {
141 w2(j) = arma::as_scalar(B*
eta.row(idx(j, i)).t());
144 for (
unsigned j=0; j <
n; j++) {
145 w2(j) = arma::as_scalar(B*
eta.row(j).t());
148 res.col(i) = (w1+w2)/std::sqrt(static_cast<double>(
n));
163 const arma::umat &idx,
165 unsigned p =
ord.n_cols;
166 arma::mat res(R, 2*p);
170 for (
unsigned i=0; i < R; i++) {
171 arma::mat wi = this->
sample(idx);
172 for (
unsigned j=0; j < p; j++) {
173 arma::vec t0 =
inp.col(j);
174 if (!idx.is_empty()) {
175 t0 = t0.elem(idx.col(j));
177 res(i, j*2) = SupTest(wi.col(j));
178 res(i, j*2+1) = L2Test(wi.col(j), t0);
arma::mat obs()
Calculate observed cumulative residual process.
arma::mat ic
Influence curve.
arma::mat sample(const arma::umat &idx=arma::umat())
Simulate one process under the null hypothesis of a correctly specified model.
arma::vec rnorm()
Draw n samples from standard normal distribution.
arma::mat eta
Cumulative derivative of residuals.
Generic class for cumulative residuals.
arma::umat ord
Stores order of observations to cumulate after.
arma::mat dr
Derivative of residuals wrt model parameters.
arma::mat inp
Variable to order residuals after.
arma::vec b
Bandwidth of moving average.
cumres(const arma::vec &r, const arma::mat &dr, const arma::mat &ic)
Constructor.
void order(const arma::mat &inp, arma::vec b=arma::vec())
Set variables to order after and bandwidth.