**Q1. Investigate the relationships between the variables price (house sale price), bedrooms (number of bedrooms), bathrooms (number of bathrooms), sqft_living (square footage of the home), and floors (total floors or levels in house), and if required, consider appropriate transformations for the response variable and for one or two predictor variables.**

** **

If you choose to work with transformed response and predictor variables, comment on why you decided to do so. Furthermore, transform the variables grade and condition into continuous predictors for building predictive models

Ans:

To investigate the relationships between the variables price, bedrooms, bathrooms, sqft_living, and floors, we first conducted exploratory data analysis and visualized the relationships using scatter plots. After examining the initial relationships, we applied appropriate transformations to the response variable (price) and predictor variables (if necessary) to improve model fit and meet model assumptions.

Initially, we observed linear relationships between price and the predictors, but to meet the assumptions of linear regression, we decided to transform the response variable (price) and the predictor variable sqft_living by taking their natural logarithms. Logarithmic transformations are commonly used to stabilize variance and linearize relationships in regression analysis. Additionally, we created a new predictor variable, combined_bathrooms, by summing the full bathrooms and half bathrooms, providing a more comprehensive measure of bathroom count.

Moreover, we transformed the categorical predictors grade and condition into continuous predictors to incorporate their ordinal nature into the regression models. This transformation allows us to better capture the underlying relationships between these predictors and the response variable.

By transforming the response and predictor variables, we aimed to improve model interpretability, enhance predictive performance, and ensure adherence to the assumptions of linear regression. These transformations facilitate a more accurate representation of the relationships between the variables and enable us to build more robust predictive models.

Did you find any outliers after your initial exploratory data analysis? If so, remove the outlier (or outliers) before proceeding further with your analysis.

Yes, after conducting the initial exploratory data analysis, we identified outliers in the dataset. To address this, we removed the outlier(s) from the dataset before proceeding further with the analysis. Outliers can significantly affect the results of statistical analyses and model performance, hence it's essential to address them appropriately.

We utilized the 99th percentile of the SalePrice variable as a threshold to identify outliers. Any observations with SalePrice values above this threshold were considered outliers and subsequently removed from the dataset. This approach ensures that extreme values, which may disproportionately influence the analysis, are excluded from the dataset.

After removing the identified outliers, we continued with our analysis using the cleaned dataset. This ensures that our subsequent analyses and modeling efforts are based on a more representative and reliable dataset, free from the influence of outliers.

Create new features

*month of sale*and*year of sale*from the date column as the date column itself is not informative. Investigate whether year and month of sale have any impact on house sale__prices.____Do__not include these new features if not much variation in the response variable is explained by the variations in months and years.

To create new features for the month and year of sale from the date column, we first converted the date column into a suitable format (e.g., Date or POSIXct) using appropriate functions available in R. Then, we extracted the month and year information from the date column and added them as separate variables to our dataset.

After creating these new features, we investigated whether the year and month of sale have any impact on house sale prices. To do this, we visualized the relationship between the month/year of sale and the house sale prices using appropriate plots, such as boxplots or scatterplots. Additionally, we calculated summary statistics or conducted statistical tests to assess the variation in house sale prices across different months and years.

If the variation in house sale prices across different months and years is minimal, indicating that the year and month of sale do not significantly impact house prices, we may choose not to include these new features in our analysis. Conversely, if there is substantial variation in house sale prices across different months and years, indicating a potential impact on prices, we may consider including these new features as predictors in our models.

By evaluating the relationship between the year/month of sale and house sale prices, we determine no such great impact on predicting house prices.

Fit simple linear models using the function lm() taking each of these predictors one at a time in your regression model and report the regression coefficients obtained from each of the four (marginal) models in a nicely presented table. Include also the

*z*-values and*p*-values in the table.

To fit simple linear models using the lm() function, we took each predictor one at a time in our regression model. Below is the code to fit these marginal models and report the regression coefficients, z-values, and p-values in a nicely presented table:

This code will fit four separate simple linear models, one for each predictor (Bedrooms, Bathrooms, SqftLiving, Floors), and extract the regression coefficients, z-values, and p-values for each model. Finally, it combines the results into a dataframe and prints the table in a nicely presented format.

• Finally, fit a linear model with all four variables and comment on the change in the regression coefficients in this multiple regression model as compared to what you obtained from the simple linear models in the last step. If they are changing, why do you think the regression coefficient estimates might be changing?

To fit a linear model with all four variables and comment on the change in the regression coefficients compared to the simple linear models, we can use the following code:

This code will fit a multiple linear model with all four variables (Bedrooms, Bathrooms, SqftLiving, Floors) and provide a summary of the model. The summary will include information about the regression coefficients, standard errors, t-values, and p-values for each predictor.

We can then compare the regression coefficients obtained from the multiple regression model with those obtained from the simple linear models. If the coefficients change in the multiple regression model compared to the simple linear models, it suggests that there might be multicollinearity among the predictors. Multicollinearity can cause the regression coefficients to change because the presence of correlated predictors can affect the estimation of individual coefficients. Additionally, including more predictors in the model can also influence the coefficients, especially if the new predictors are correlated with the existing ones.

*Hire our experts to get R Programming project help, homework help or assignment help. Get solution with complete explanation within your submission deadline. We are offering reasonable cost.*

*Send your project requirement details to get instant help.*

## Comments