tvslm <- function(y, X){
y <- matrix(y)
X <- as.matrix(X)
X <- cbind(intercept = rep(1,length(y)),X)
pred <- (solve(t(X)%*%X))%*%t(X)%*%y
fit <- X %*% pred
resid <- y - fit #booot
se_temp <- sqrt(diag(as.numeric((t(resid)%*%resid)/(nrow(X)-ncol(X)))*(solve(t(X)%*%X))))
tstattemp <- pred/se_temp #test
me <- list(
predictors = pred,
SE = se_temp,
fitted.values = fit,
residuals = resid,
t.stat = tstattemp,
p = 2*(1-pt(abs(tstattemp),(nrow(X)-ncol(X))))
)
class(me) <- append(class(me), "tvslm")
return(me)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.