Why can't do ridge regression with one predictor? I'm trying to fit a ridge regression model with a single predictor. However, when I try to do so in three different R packages I get the three following errors:
Error in colMeans(X[, -Inter]) : 
  'x' must be an array of at least two dimensions

Error in if (is.null(np) | (np[2] <= 1)) stop("x should be a matrix with 2 or more columns") : 
  argument is of length zero

Error in colMeans(x[, -Inter]) : 
  'x' must be an array of at least two dimensions

The bottom line from these errors is that x needs to have at least 2 dimensions. Why is this necessary for ridge regression? Does this mean that I can't use ridge regression with a single predictor? Just seems weird I couldn't use ridge regression to get regularization for something like a t-test.
Here is my code:
library(lmridge)
library(glmnet)
library(ridge)

# data 
set.seet(100)
y <- rnorm(100)
x <- rbinom(100, 1, .5)
z <- rbinom(100, 1, .5)
data <- cbind.data.frame(y, x, z)

# ridge
linearRidge(y ~ x, data = data)

# glmnet
glmnet(data$x, data$y, nlambda = 25, alpha = 0, family = 'gaussian', lambda = .5)

# lmridge
lmridge(y ~ x, data = data, scaling = "sc", K = seq(0, 1, 0.001))

 A: StatQuest does ridge with one predictor just fine in his video.
https://youtube.com/watch?v=Q81RR3yKn30
The method is somewhat silly to use in a regression with just one parameter, but I am surprised the common software implementation don’t allow it. Perhaps the StatQuest example could make sense in some setting.
But that’s just an issue with the software implementation. You’re still able to write your parameter vector as $\hat{\beta}_R = (X^TX+\lambda I)^{-1}X^Ty$ and do the calculation.
($I$ is the identity matrix; $\lambda$ is your ridge regression hyperparameter.)
Another popular software implementation of ridge regression is the sklearn packing in Python. Perhaps give that a whirl.
A: As others have noticed, using Ridge regression with only a single feature is overkill. Ridge regression is used when you have many features, so you want to penalize them to avoid overfitting. From your comments, it seems like your idea is to use Ridge regression as a form of prior

There's lot of research showing that experimental intervention effect sizes in the scientific literature tend to be exaggerated. So why not try and regularize the estimated treatment effect towards zero?

As you can learn from the Is Bayesian Ridge Regression another name of Bayesian Linear Regression? thread, Ridge regression is a MAP estimate of a Bayesian linear regression with a Gaussian prior for the parameters. Why not just use a Bayesian model? Ridge regression is a poor man's implementation of such a model, going full Bayesian enables you to be more flexible with model definition and would enable you to define the priors more explicitly. Ridge regression would also somewhat work like this, but it is the wrong tool for the job.
