R/rmultreg.R

Defines functions rmultreg

Documented in rmultreg

rmultreg <- function(n, k = 1, minimum = 0, maximum = 1, p = 0.5, dfnoise = 100, sdnoise = 1) { 
    beta <- runif(n = k+1, min = minimum, max = maximum)*rbinom(n = k+1, size = 1, prob = p)
    xy <- data.frame(matrix(rnorm(k*n), nrow = n))
    names(xy) <- paste("x", 1 : k, sep = "")
    noise <-  rt(n, df = dfnoise)*sdnoise*sqrt((dfnoise - 2)/dfnoise)
    y <- as.matrix(xy)%*%beta[-1] + beta[1] + noise
    names(beta) <- c("Intercept", names(xy))
    xy$y <- as.vector(y) 
    names(xy)[k+1] <- "y"
    return(list(data = xy, coefficients = beta))
}

Try the ADVICE package in your browser

Any scripts or data that you put into this service are public.

ADVICE documentation built on April 16, 2021, 9:07 a.m.