knitr::opts_chunk$set( error = TRUE, collapse = TRUE, comment = "#>", out.width = "100%" )
alpha <- runif(n = 1, min = -1, max = 1) beta <- runif(n = 1, min = -1, max = 1) sigmax2 <- runif(n = 1, min = 0, max = 1) sigmae2 <- runif(n = 1, min = 0, max = 1) mux <- runif(n = 1, min = -1, max = 1) muepsilon <- 0 A <- S <- matrixR::ZeroMatrix(3) A[1, ] <- c(0, beta, 1) diag(S) <- c(0, sigmax2, sigmae2) colnames(A) <- rownames(A) <- c("y", "x", "e") I <- matrixR::IdentityFrom(A) IminusA <- I - A E <- Ryacas::as_r(solve(Ryacas::ysym(I) - Ryacas::ysym(A))) Filter <- diag(2) Filter <- cbind(Filter, 0) colnames(Filter) <- c("y", "x", "e") rownames(Filter) <- c("y", "x") u <- as.matrix(c(alpha, mux, 0)) v <- as.matrix(c(alpha + (beta * mux), mux, 0.00)) rownames(u) <- rownames(v) <- c("y", "x", "e") colnames(u) <- "u" colnames(v) <- "v" C <- Ryacas::as_r( solve( Ryacas::ysym(I) - Ryacas::ysym(A) ) * Ryacas::ysym(S) * t( solve(Ryacas::ysym(I) - Ryacas::ysym(A)) ) ) C.scaled <- stats::cov2cor(C) M <- Ryacas::as_r( Ryacas::ysym(Filter) * solve( Ryacas::ysym(I) - Ryacas::ysym(A) ) * Ryacas::ysym(S) * t( solve(Ryacas::ysym(I) - Ryacas::ysym(A)) ) * t(Ryacas::ysym(Filter)) ) M.scaled <- Filter %*% C.scaled %*% t(Filter) g <- as.matrix( Ryacas::as_r( Ryacas::ysym(Filter) * Ryacas::ysym(v) ) )
\begin{equation}
\begin{split}
y &= \alpha + \beta x + \varepsilon \
y &= r alpha
+ \left( r beta
x \right) + \varepsilon
\end{split}
\end{equation}
eq <- paste( "e by y 1", "\n", "y on x", beta, "\n", "e with e", sigmae2, "\n", "x with x", sigmax2, "\n", "y on 1", alpha, "\n", "x on 1", mux, "\n" ) n <- 100 Data <- ramR::Eq2Data(eq, n = n, empirical = TRUE) mu <- as.matrix(colMeans(Data)) Sigma <- cov(Data)
testthat::test_that("g.", { for (i in seq_len(nrow(g))) { for (j in seq_len(ncol(g))) { testthat::expect_equal( g[i, j], mu[i, j], check.attributes = FALSE ) } } }) testthat::test_that("M.", { for (i in seq_len(nrow(M))) { for (j in seq_len(ncol(M))) { testthat::expect_equal( M[i, j], Sigma[i, j], check.attributes = FALSE ) } } }) testthat::test_that("n.", { testthat::expect_equal( n, dim(Data)[1], check.attributes = FALSE ) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.