Problem 1: Model Selection

We assume that we have a dataset for the response variable carcass weight (CW) and for some predictor variables

Use a fixed linear effects model and determine which of the predictor variables are important for the response.

The data is available from https://charlotte-ngs.github.io/gelasmss2021/data/gel_model_sel_ex02.csv.

Hint

  • Use the function lm in R to fit the fixed linear effects model
  • Use either Mallow \(C_p\) statistic or the adjusted coefficient of determination \(R_{adj}^2\) or AIC as model selection criteria
  • Use the backward model selection approach

Your Solution

Start with reading the data into a tibble or a dataframe.

# reading data

Convert all fixed effects into factors using the function as.factor()

# convert fixed effects to factors using as.factor()

Define the full model

# define full model using function lm()

Use result of full model as input for a function like stepAIC() from package MASS

# use function MASS:stepAIC()

Latest Changes: 2021-04-23 10:47:48 (pvr)

LS0tCnRpdGxlOiBHZW5ldGljIEV2YWx1YXRpb24gLSBOb3RlYm9vayAyCmF1dGhvcjogUGV0ZXIgdm9uIFJvaHIKZGF0ZTogMjAyMS0wNC0yNgpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sKLS0tCgoKYGBge3Igc2V0dXAsIGluY2x1ZGU9RkFMU0V9CmtuaXRyOjpvcHRzX2NodW5rJHNldChlY2hvID0gVFJVRSkKYGBgCgpgYGB7ciBwcjAxLXJlYWQtZGF0YSwgZWNobz1GQUxTRSwgbWVzc2FnZT1GQUxTRSwgd2FybmluZz1GQUxTRX0Kc19kYXRhX2ZpbGUgPC0gImh0dHBzOi8vY2hhcmxvdHRlLW5ncy5naXRodWIuaW8vZ2VsYXNtc3MyMDIxL2RhdGEvZ2VsX21vZGVsX3NlbF9leDAyLmNzdiIKdGJsX21vZHNlbCA8LSByZWFkcjo6cmVhZF9jc3YyKHNfZGF0YV9maWxlKQpgYGAKCgojIyBQcm9ibGVtIDE6IE1vZGVsIFNlbGVjdGlvbgpXZSBhc3N1bWUgdGhhdCB3ZSBoYXZlIGEgZGF0YXNldCBmb3IgdGhlIHJlc3BvbnNlIHZhcmlhYmxlIGBjYXJjYXNzIHdlaWdodGAgKENXKSBhbmQgZm9yIHNvbWU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