the previous problem this is referring to is: Please do it in R studio (install
ID: 2932396 • Letter: T
Question
the previous problem this is referring to is:
Please do it in R studio (install package "alr4" then load data file "salary", you must install alr4 package first to access the data file ) please show code and work.
2. Using the salary data of the previous problem, one fitted mean function is E(salary!sex, year) = 18223-571 sex + 741 year + 169 sex × year (a) Give the coefficients in the estimated mean function if sex were coded so that males had the value 2 and females had the value 1 (the coding given to get the mean function above was 0 for males and 1 for females). (b) Give the estimated coefficients if sex were coded as -1 for males and +1 for females.Explanation / Answer
(a)
Given mean function when sex = 0 for males and sex = 1 for females
E(salary| sex,year) = 18223 - 571 sex + 741 year + 169 sex * year
For male, the mean equation becomes,
E(salary| sex,year) = 18223 - 571 * 0 + 741 year + 169 * 0 * year
E(salary| sex,year) = 18223 + 741 year ----(1)
For female, the mean equation becomes,
E(salary| sex,year) = 18223 - 571 * 1 + 741 year + 169 * 1 * year
E(salary| sex,year) = 17652 + 910 year ----(2)
Now, let mean function when sex = 2 for males and sex = 1 for females be
E(salary| sex,year) = a0 + a1 sex + a2 year + a3 sex * year
For male, the mean equation becomes,
E(salary| sex,year) = a0 + a1 * 2 + a2 year + a3 * 2 * year
E(salary| sex,year) = a0 + 2a1 + (a2 + 2a3) year -----(3)
For female, the mean equation becomes,
E(salary| sex,year) = a0 + a1 * 1 + a2 year + a3 * 1 * year
E(salary| sex,year) = a0 + a1 + (a2 + a3) year -----(4)
From (1) and (3), we get
a0 + 2a1 = 18223
a2 + 2a3 = 741
From (2) and (4), we get
a0 + a1 = 17652
a2 + a3 = 910
Solving, we get
a0 = 17081
a1 = 571
a2 = 1079
a3 = -169
So, the mean function when sex = 2 for males and sex = 1 for females be
E(salary| sex,year) = 17081 + 571 sex + 1079 year - 169 sex * year
(b)
Now, let mean function when sex = -1 for males and sex = +1 for females be
E(salary| sex,year) = a0 + a1 sex + a2 year + a3 sex * year
For male, the mean equation becomes,
E(salary| sex,year) = a0 + a1 * (-1) + a2 year + a3 * (-1) * year
E(salary| sex,year) = a0 - a1 + (a2 - a3) year -----(5)
For female, the mean equation becomes,
E(salary| sex,year) = a0 + a1 * 1 + a2 year + a3 * 1 * year
E(salary| sex,year) = a0 + a1 + (a2 + a3) year -----(6)
From (1) and (5), we get
a0 - a1 = 18223
a2 - a3 = 741
From (2) and (6), we get
a0 + a1 = 17652
a2 + a3 = 910
Solving, we get
a0 = 17937.5
a1 = -285.5
a2 = 825.5
a3 = 84.5
So, the mean function when sex = -1 for males and sex = +1 for females be
E(salary| sex,year) = 17937.5 - 285.5 sex + 825.5 year + 84.5 sex * year
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.