Problem 1: Interactions
Use the following dataset on Breed
,
Breast Circumference
and Body Weight
and fit a
fixed linear effects model with Body Weight
as response and
Breed
and Breast Circumference
as predictors
and include an interaction term between the two predictors. Compute the
expected difference in Body Weight
for two animals which
differ in
Breast Circumference by $1cm$ for every
Breed`.
The dataset is available under
[1] "https://charlotte-ngs.github.io/asmss2023/data/asm_bw_flem.csv"
https://charlotte-ngs.github.io/asmss2023/data/asm_bw_flem.csv
Your Solution
- Read the data
- Fit fixed linear effects model for Body Weight using
Breed
and Breast Circumference
and the
interaction with function lm()
- From the solution of the
summary()
of the
lm()
result get the regression coefficient and the
interaction effects and compute the expected difference in
Body Weight
for all three breeds.
Problem 2: Simulation
Use the following values for intercept and regression slope for
Body Weight
on Breast Circumference
to
simulate a dataset of size \(N\). What
is the number for \(N\) that has to be
chosen such that the regression analysis of the simulated data gives the
same result as the true regression slope.
The true values are:
- Intercept: \(-1070\)
- Regression slope: \(8.7\)
- Residual standard error: \(12\)
Hints
- Start with \(N=10\), simulate a
dataset and analyse the data with
lm()
- If the result (rounded to 1 digits after decimal point) is not the
same then double the size of the dataset, hence use, \(N=20\)
- Continue until you get close to the true value.
- Assume that the random resiudals follow a normal distribution with
mean zero and standard devation equal to \(12\)
- Take breast circumference to be normally distributed with a mean of
\(180\) and a standard deviation of
\(2.6\)
- Use a linear regression model with an intercept to model expected
body weight based on breast circumference.
Your Solution
- Start with \(N=10\), simulate a
dataset and analyse the data with
lm()
- If the result (rounded to 1 digits after decimal point) is not the
same then double the size of the dataset, hence use, \(N=20\)
- Continue until you get close to the true value.
Latest Changes: 2023-05-07 13:49:44 (pvr)
LS0tCnRpdGxlOiBBcHBsaWVkIFN0YXRpc3RpY2FsIE1ldGhvZHMgLSBOb3RlYm9vayA1CmF1dGhvcjogUGV0ZXIgdm9uIFJvaHIKZGF0ZTogJzIwMjMtMDQtMjQnCm91dHB1dDogaHRtbF9ub3RlYm9vawpwYXJhbXM6CiAgZG9jdHlwZToKICAgIGxhYmVsOiBE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