0% found this document useful (0 votes)
7 views6 pages

Presentation Group 4

Uploaded by

laibasajal484
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Presentation Group 4

Uploaded by

laibasajal484
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

R Programming

Regression Analysis
1: Simple linear regression
2: Multiple regression
3: OLS regression
R Programming overview
◦ R is a programming language and software
environment used for statistical analysis, data
visualization, and data modeling. It is widely
used by statisticians, data scientists, and
researchers for tasks such as:Data cleaning and
manipulation.Exploratory data analysis
(EDA).Statistical modeling and hypothesis
testing.Advanced analytics such as machine
learning and time series forecasting.The base R
package includes tools for data manipulation
and statistical modeling, while numerous
additional packages (e.g., ggplot2, dplyr, and
caret) extend its functionality.
Regression Analysis
◦ Regression is a statistical technique for modeling
the relationship between a dependent (response)
variable and one or more independent (predictor)
variables. Common types of regression include:
◦ 1. Simple Linear Regression:
Models the relationship between one dependent
variable and one independent variable.
Formula: Y = B°+B¹+e
B°: Intercept (constant term) ,B¹:Slope (coefficient of
X) ,E: Error term.
◦ In R:1-Load data:. data <- data.frame(x = c(1, 2, 3,
4, 5), y = c(2, 4, 5, 4, 5)) 2:Fit simple linear
regression model: model <- lm(y ~ x, data = data)
3:Summary of the model: summary(model) 4:Plot
the regression line: plot(data$x, data$y, main =
“Simple Linear Regression”, xlab = “X”, ylab =
“Y”)abline(model, col = “blue”)
To be continue:

Extends simple regression to include multiple independent


variables.Formula: Y=B°+B¹X¹+ B²X²+.…….+BpXp+eIn R:#
Load datadata <- data.frame(x1 = c(1, 2, 3, 4, 5), x2 =
c(2, 3, 4, 5, 6), y = c(2, 4, 5, 4, 5))# Fit multiple
linear regression modelmodel <- lm(y ~ x1 + x2, data = data)#
Summary of the modelsummary(model)3. Ordinary Least
2: Multiple regression : Squares (OLS)OLS is a method for estimating the parameters
of a linear regression model by minimizing the sum of the
squared residuals.Residual: The difference between the
observed value and the predicted value.OLS is the standard
approach used in both simple and multiple linear regression
in R. When you use the lm() function, it performs OLS under
the hood.
Steps to Run Regressions
in R
◦ 1. Load and Prepare Data
Use packages like dplyr for data manipulation and
cleaning.Ensure there are no missing or inconsistent values.
◦ 2. Fit the Regression Model
Use the lm() function to fit the model.Syntax:
lm(dependent_variable ~ independent_variable(s), data =
dataset).
◦ 3. Analyze Model Output
Use summary() to evaluate model coefficients, , p-values,
and residuals.
◦ 4. Visualize the Results
Use base R plotting functions or packages like ggplot2.
To be continue:
◦ 5:Validate the Mode:
Check assumptions (e.g., linearity, normality of
residuals, homoscedasticity, independence).
Use diagnostic plots:par(mfrow = c(2, 2)) # Set up
for multiple plotsplot(model)
◦ 6. Predict:
Use predict() to make predictions on new data.
New_data <- data.frame(x1 = c(6, 7), x2 = c(7,
8))predictions <- predict(model, newdata =
new_data)print(predictions)By following these steps,
you can effectively use R for regression analysis, from
simple models to complex multiple regressions with
OLS estimation.

You might also like