glmnet Ridge Regression Plot makes no sense (to me at least) I have a data set with around 50 variables and I am applying ridge and lasso on this data set. What I´ve noticed is, that the plot for the lambda values does differ from the mean values I get when calculating the corresponding mean(lambda).
For example log(10000)=4 should have a mean of around 2100 if looking at the plot but it calculates a mean of 5200. In that case it would mean that the plot is wrong.
Same has been observed for Lasso.
Since I am student and just started with Statistics I would kindly ask to forgive me if I am being dumb with this question.

install.packages("glmnet")
?glmnet
library(glmnet)

# PREDICTOR MATRIX
x = model.matrix(tc ~ ., data = df_6)[,-1] #response vector
y = df_6$tc
grid = 10^seq(10,-2,length=100)

# DEFINE TRAIN AND TEST SET FOR RIDGE AND LASSO REGRESSION
set.seed (10)
train = sample(1:nrow(x), nrow(x)/2)
test=(-train)
y.test=y[test]

# PERFORM RIDGE REGRESSION
ridge.mod = glmnet(x[train ,], y[train], alpha =0, lambda =grid)
plot(ridge.mod)

# CV FOR COMPARISON WITH OTHER MODELS
cv.out_ridge = cv.glmnet( x[train,], y[train], alpha = 0) #by default 10 fold CV. Kann mit nfolds verändert werden.
plot(cv.out_ridge)                   # plot log lambda
lambda.opt_ridge = cv.out_ridge$lambda.min
lambda.opt_ridge
cv.out_ridge$lambda
cv.out_ridge$lambda.1se
ridge.pred = predict(ridge.mod,s=lambda.opt_ridge,newx=x[test,])
mean((ridge.pred-y.test)^2)


To check if the plots are wrong (they aren't), check what the mean CV MSE was for the selected lambda (in your case lambda.min, so looks like the first lambda in the sequence with a MSE of slightly below 2000).
cv.out_ridge$cvm[cv.out_ridge$lambda==cv.out_ridge$lambda.min]

As to why the scores are not similar between CV and a test set... ideally they will be similar, if your model is great... if.
