Projpred varsel specifying search_terms

Could somebody show me how to specify the search_terms list in the varsel() function?

Here is a minimal example, model first …


n ← 30
d ← 5
x ← matrix(rnorm(nd), nrow=n)
y ← x[,1] + 0.5
data ← data.frame(x,y)
fit ← stan_glm(y ~ X1 + X2 + X3 + X4 + X5,

Then varsel on all terms in the model works OK.

vs1 ← varsel(fit)

But how to select a subset of terms?

vs2 ← varsel(fit, search_terms=c(“X1”,“X2”,“X3”), method=“forward”)

vs3 ← varsel(fit, search_terms=list(“X1”,“X2”,“X3”), method=“forward”)

tt ← terms(fit)
term_list ← as.list(attr(tt, “variables”))
vs4 ← varsel(fit, search_terms=tt, method=“forward”)

All of these show the same error message
Error in sub[“kl”, i] : incorrect number of dimensions

What am I doing wrong?

Sorry for the delay. We’re lacking a proper documentation and vignette for search_terms. There’s some discussion at Advice on using search_terms in projpred - #4 by AlejandroCatalina

I have collected this and similar questions here. Perhaps the connection to related threads helps until this is resolved in the projpred package (e.g., by an explanation in the documentation).

Also sorry for delay for reply from me!

I could not find much in the forum searching for “varsel”. Searching on projpred shows a lot more about using varsel.

I have been looking at this in more detail– I will post something on the forum in the next day or so.


@ACB, you need to include the intercept ("1") in search_terms. If you do this and try again with projpred’s most recent CRAN (or GitHub, shouldn’t matter) version, do you still get the error sub["kl", i] : incorrect number of dimensions?

1 Like