knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Download and install the package use devtools
:
library(devtools) install_github("sophiaycl/HW2")
Load the package with the usual R commands:
library(HW2)
HW2
has three functions:
To solve $x$ for a linear system $Ax = b$, the function has the basic form of:
solve_ols(A, b, ncores = 1, type ='GS', iterNum = 10000)
$A$ is required to be a $n \times n$ square invertible matrix, $b$ is a vector with the same dimension $n$.
An example is shown here.
D = diag(rep(10, 10)) N = matrix(rnorm(50), ncol = 10) A = D + N b = runif(10) x_JC = solve_ols(A, b, type = 'JC', iterNum = 500) x_GS = solve_ols(A, b, iterNum = 500) print(cbind(x_JC, x_GS))
$Y = X \beta + E$.
An example is given as:
n = 500; p = 6; r = 30 X = matrix(rnorm(n * p), nrow = n) true.beta = 3 * runif(p) y = X %*% true.beta + rnorm(n) beta.unif = algo_leverage(X, y, sampSize = r, sampleType = 'Unif') beta.lev = algo_leverage(X, y, sampSize = r, sampleType = 'Lev') print(cbind(beta.unif, beta.lev))
A similar example is given as:
n = 300; p = 100 X = matrix(rnorm(n * p), nrow = n) true.beta = 3 * runif(p) Y = X %*% true.beta + rnorm(n) beta.elnet = elnet_coord(X, Y, a = 0.5, lambda = 5, GLMNET = FALSE) beta.glm = elnet_coord(X, Y, a = 0.5, lambda = 5, GLMNET = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.