Question
5)Build a function my.ls() which performs the least square estimation for a continuous response variable y regressed on two predictors x1 which is a numeric
5)Build a function my.ls() which performs the least square estimation for a continuous response variable y regressed on two predictors x1 which is a numeric predictor and x2 which is a categorical predictor. You may assume that your model contains an intercept. Test the function on the ChickWeight dataset in R, where y is weight, x1 is Time (assumed to be continuous) and x2 is Diet, i.e., check if the function can reproduce the estimated beta coefficients from
data(ChickWeight) fit <- lm(ChickWeight$weight~ChickWeight$Time+ChickWeight$Diet) fit$coef
#using R, the code step by step so I learn
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started