Problem 1: Sum Contrasts
Use the following dataset on Body Weight
and
Breed
of beef cattle animals. The data is available
from
[1] "https://charlotte-ngs.github.io/asmss2023/data/asm_bw_breed.csv"
https://charlotte-ngs.github.io/asmss2023/data/asm_bw_breed.csv
Fit a fixed linear model with Body Weight
as response
and Breed
as predictor variable. Use the sum
contrasts for reporting the different effects in the model. Validate the
estimates by computing the estimates based on a solution of the least
squares normal equations.
Your Solution
- Read the dataset given by the above link
- Change contrasts for the factor
Breed
to
sum
contrasts
- Fit linear model with
Body Weight
as response and
Breed
as predictor
- Compute solutions of least squares normal equation
- Use contrasts matrix to determine the estimable functions
- Compare values of estimable functions to output of
lm()
Problem 2: Custom Contrasts
Use the dataset from Problem 1 and use your own contrasts. Your new
contrasts should compute the intercept estimate as is done in the
sum
contrasts. The Breed
effects should be
computed the same way as is done in the treatment
contrast.
Your Solution
- Construct the matrix of estimable functions and of the linear
combination for the intercept
- Compute the contrasts matrix
- Fit the linear model using the custom contrasts matrix
Latest Changes: 2023-04-02 12:56:01 (pvr)
LS0tCnRpdGxlOiBBcHBsaWVkIFN0YXRpc3RpY2FsIE1ldGhvZHMgLSBOb3RlYm9vayA0CmF1dGhvcjogUGV0ZXIgdm9uIFJvaHIKZGF0ZTogJzIwMjMtMDMtMjAnCm91dHB1dDogaHRtbF9ub3RlYm9vawpwYXJhbXM6CiAgZG9jdHlwZToKICAgIGxhYmVsOiBEb2N1bWVudCBUeXBlCiAgICB2YWx1ZTogc29sdXRpb24KICAgIGNob2ljZXM6CiAgICAtIGV4ZXJjaXNlCiAgICAtIHNvbHV0aW9uCiAgICAtIG5vdGVib29rCiAgaXNvbmxpbmU6CiAgICBsYWJlbDogT25saW5lICh5L24pCiAgICB2YWx1ZTogdHJ1ZQogICAgY2hvaWNlczoKICAgIC0gdHJ1ZQogICAgLSBmYWxzZQotLS0KCgoKYGBge3Igc2V0dXAsIGluY2x1ZGU9RkFMU0V9CmtuaXRyOjpvcHRzX2NodW5rJHNldChlY2hvID0gVFJ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