1 | lsfitNci(x, y, alpha = 0.05)
|
x |
|
y |
|
alpha |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (x, y, alpha = 0.05)
{
x <- as.matrix(x)
if (nrow(x) != length(y))
stop("Length of y does not match number of x values")
m <- cbind(x, y)
m <- elimna(m)
y <- m[, ncol(x) + 1]
temp <- lsfit(x, y)
x <- cbind(rep(1, nrow(x)), m[, 1:ncol(x)])
xtx <- solve(t(x) %*% x)
h <- diag(x %*% xtx %*% t(x))
hc3 <- xtx %*% t(x) %*% diag(temp$res^2/(1 - h)^2) %*% x %*%
xtx
df <- nrow(x) - ncol(x)
crit <- qt(1 - alpha/2, df)
al <- ncol(x)
ci <- matrix(NA, nrow = al, ncol = 3)
for (j in 1:al) {
ci[j, 1] <- j
ci[j, 2] <- temp$coef[j] - crit * sqrt(hc3[j, j])
ci[j, 3] <- temp$coef[j] + crit * sqrt(hc3[j, j])
}
print("Confidence intervals for intercept followed by slopes:")
list(ci = ci, stand.errors = sqrt(diag(hc3)))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.