[R] Bias and variance tradeoff

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Thu Apr 27 00:11:36 CEST 2023


Off topic I think. This is a statistical question, not an R programming
question.

There are certainly many internet tutorials on this  -- e.g. "bias and
variance in linear models" as a search term. You might also consider search
terms like "shrinkage estimators", "penalized regression".
"regularization", "ridge regression,"and the like if you care to go deeper.

Cheers,
Bert

On Wed, Apr 26, 2023 at 1:32 PM varin sacha via R-help <r-help using r-project.org>
wrote:

> Dear R-experts,
>
> Here below a toy example to calculate the MSE (mean squared error).
>
> Starting from this equation : MSE = bias^2 + variance + irreducible error
>
> I am trying to get the bias and the variance in addition to the MSE. How
> to get them both?
>
> Many thanks for your help.
>
>
> #########################################################
> #Data
> y=c(23,34,54,34,23,34,43,45,56,65,45,42,32,35,37,41,54,56,53,45)
> x1=c(2,4,3,5,4,6,4,3,2,1,2,3,4,3,5,6,7,6,4,3)
> x2=c(11,12,13,21,14,13,15,17,18,16,21,21,23,19,11,10,19,17,16,11)
> x3=c(45,46,34,24,47,48,50,40,41,39,37,34,50,56,53,51,37,48,49,53)
>
> #Fit the model
> model=lm(y~x1+x2+x3)
>
> #Calculate MSE
> model_summ=summary(model)
> mean(model_summ$residuals^2)
> ###########################################################
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list