`init_refmodel.Rd`

Initializes a structure that can be used as a reference fit for the projective variable selection. This function is provided to allow construction of the reference fit from arbitrary fitted models, because only limited information is needed for the actual projection and variable selection.

init_refmodel(z, y, family, x = NULL, predfun = NULL, dis = NULL, offset = NULL, wobs = NULL, wsample = NULL, intercept = TRUE, cvfun = NULL, cvfits = NULL, ...)

z | Predictor matrix of dimension |
---|---|

y | Vector of length |

family | family object giving the model family |

x | Predictor matrix of dimension |

predfun | Function that takes a |

dis | Vector of length |

offset | Offset to be added to the linear predictor in the projection. (Same as in
function |

wobs | Observation weights. If omitted, equal weights are assumed. |

wsample | vector of length |

intercept | Whether to use intercept. Default is |

cvfun | Function for performing K-fold cross-validation. The input is an |

cvfits | A list with K elements, that has the same format as the value returned by |

... | Currently ignored. |

An object that can be passed to all the functions that take the reference fit as the first argument, such as varsel, cv_varsel, proj_predict and proj_linpred.

# generate some toy data set.seed(1) n <- 100 d <- 10 x <- matrix(rnorm(n*d), nrow=n, ncol=d) b <- c(c(1,1),rep(0,d-2)) # first two variables are relevant y <- x %*% b + rnorm(n) # fit the model (this uses rstanarm for posterior inference, # but any other tool could also be used) fit <- stan_glm(y~x, family=gaussian(), data=data.frame(x=I(x),y=y))#> Error in stan_glm(y ~ x, family = gaussian(), data = data.frame(x = I(x), y = y)): could not find function "stan_glm"draws <- as.matrix(fit)#> Error in as.matrix(fit): object 'fit' not founda <- draws[,1] # intercept#> Error in eval(expr, envir, enclos): object 'draws' not foundb <- draws[,2:(ncol(draws)-1)] # regression coefficients#> Error in eval(expr, envir, enclos): object 'draws' not foundsigma <- draws[,ncol(draws)] # noise std#> Error in eval(expr, envir, enclos): object 'draws' not found# initialize the reference model structure predfun <- function(xt) t( b %*% t(xt) + a ) ref <- init_refmodel(x,y, gaussian(), predfun=predfun, dis=sigma)#> Error in t(b %*% t(xt) + a): object 'a' not found#> Error in get_refmodel(fit, ...): object 'ref' not foundvarsel_plot(vs)#> Error in "vsel" %in% class(object): object 'vs' not found# pass in the original data as 'reference'; this allows us to compute # traditional estimates like Lasso dref <- init_refmodel(x,y,gaussian()) lasso <- cv_varsel(dref, method='l1') # lasso#> [1] "Performing selection for each fold.." #> | | | 0% | |======= | 10% | |============== | 20% | |===================== | 30% | |============================ | 40% | |=================================== | 50% | |========================================== | 60% | |================================================= | 70% | |======================================================== | 80% | |=============================================================== | 90% | |======================================================================| 100% #> [1] "Performing the selection using all the data.." #> [1] "Done."