Write FULL R code to solve this:

My data:
# Load the data
load("C:/Users/kylek/OneDrive/Desktop/Stats 2/CroqPain_new.rda")
load("C:/Users/kylek/OneDrive/Desktop/Stats 2/CroqPainFix.rda")

# Setting this to not cause name errors later.
CroqPainFix <- CroqPaiFix

# Convert STOR in CroqPainFix to character
CroqPainFix$STOR <- as.character(CroqPainFix$STOR)

# Convert EMPL in CroqPain_new to integer
CroqPain_new$EMPL <- as.integer(as.character(CroqPain_new$EMPL))

# Handle NA values in EMPL in CroqPain_new
# Example: Replace NA with the mean of the column
CroqPain_new$EMPL[is.na(CroqPain_new$EMPL)] <- mean(CroqPain_new$EMPL, na.rm = TRUE)

CroqPain_new:
Column

Type

STOR character
K numeric
SIZE integer
EMPL factor
total integer
P15 integer
P25 integer
P35 integer
P45 integer
P55 integer

CroqPainFix:
Column

Type

STOR integer
EARN numeric
K numeric
SIZE integer
EMPL integer
total integer
P15 integer
P25 integer
P35 integer
P45 integer

2-1. Building Models (Part a)
Consider all observations in CroqPainFix.
Michel’s first model is shown in Table 6.27 on page 305 with some concerns. Try to improve the model that does not violate any of the basic assumptions of regression but has good predictive power. In short, you should carefully choose the explanatory variables. What are the explanatory variables of your choice?
When you run regressions, be sure to check multicollinearity.
If you want, you can try different variable selection algorithms. However, be critical and make a decision about the final model to recommend for Croq’Pain.

Michel's Model:
SUMMARY OUTPUT
Regression Statistics	Values
Multiple R	0.931
R Square	0.867
Adjusted R Square	0.826
Standard Error	38.126
Observations	60

ANOVA
Source	df	SS	MS	F	Significance F
Regression	14	426,750.607	30,482.186	20.970	0.000
Residual	45	65,411.117	1,453.580		
Total	59	492,161.724		

Coefficients Table
Variable	Coefficients	Standard Error	t Stat	P-value	Lower 95%	Upper 95%
Intercept	-364.267	98.345	-3.704	0.001	-562.345	-166.190
SIZE	0.771	0.099	7.803	0.000	0.572	0.970
EMPL	-0.866	1.466	-0.591	0.558	-3.818	2.086
total	-0.010	0.013	-0.805	0.425	-0.036	0.015
P15	0.057	0.028	2.050	0.046	0.001	0.113
P25	0.013	0.013	0.978	0.333	-0.014	0.040
P35	0.014	0.022	0.658	0.514	-0.030	0.059
P45	0.001	0.033	0.032	0.975	-0.065	0.067
P55	0.010	0.014	0.727	0.471	-0.018	0.039
INC	8.763	1.644	5.331	0.000	5.453	12.074
COMP	-2.681	2.320	-1.156	0.254	-7.354	1.992
NCOMP	-0.347	1.561	-0.222	0.825	-3.490	2.797
NREST	1.451	0.245	5.920	0.000	0.958	1.945
PRICE	-3.173	0.966	-3.283	0.002	-5.119	-1.226
CLI	0.402	0.700	0.574	0.569	-1.008	1.812


2-2. Validation by Testing (Part b)
In 2-1, you build a model using all observations in CroqPainFix. Michel wants to validate its usefulness (or accuracy) with existing data. Split CroqPainFix into the following two data sets.
CroqPainFix_50: The 50 stores opened up prior to 1994, i.e., STOR<=50.
CroqPainFix_10: The 10 stores opened in the first half of 1994, i.e., STOR>50.
Using CroqPainFix_50, re-estimate your model. That is, keep your explanatory variables from 2-1 and re-estimate their coefficients with the data set of 50 stores.
With this newly estimated model, predict the performances of the 10 stores in CroqPainFix_10. Using Croq’Pain’s performance ratio target of 26%, which of the ten stores would you have opened in 1994 according to your model?



3. Prediction (Part c)
As you validated the model (i.e., a selection of explanatory variables), let’s use the most complete estimates using CroqPainFix. With this complete model, you need to recommend which new locations Croq’Pain should open its stores among 10 locations in Table 6.28 or CroqPain_new.rda. Which locations would you recommend?