I have a data frame PlotData_df with 3 columns: Velocity (numeric), Height(numeric), Gender(categorical).

```        Velocity Height Gender
1       4.1    3.0   Male
2       3.1    4.0 Female
3       3.9    2.4 Female
4       4.6    2.8   Male
5       4.1    3.3 Female
6       3.1    3.2 Female
7       3.7    3.0   Male
8       3.6    2.4   Male
9       3.2    2.7 Female
10      4.2    2.5   Male
```

I used the following to give regression equation for complete data:

```c <- lm(Height ~ Velocity, data = PlotData_df)

summary(c)
#             Estimate Std. Error t value Pr(>|t|)
# (Intercept)   4.1283     1.0822   3.815  0.00513 **
# Velocity     -0.3240     0.2854  -1.135  0.28915
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# Residual standard error: 0.4389 on 8 degrees of freedom
# Multiple R-squared:  0.1387,  Adjusted R-squared:  0.03108
# F-statistic: 1.289 on 1 and 8 DF,  p-value: 0.2892

a <- signif(coef(c), digits = 2)
b <- signif(coef(c), digits = 2)
Regression <- paste0("Velocity = ",b," * Height + ",a)
print(Regression)
#  "Velocity = -0.32 * Height + 4.13"```

How can I extend this to display two regression equations (depending on whether Gender is Male or Female)?

Mar 7, 2022 209 views

## 1 answer to this question.

First, you'll need a linear model with Height and Gender interaction. Try:

`Fit <- lm(formula = Velocity ~ Height * Gender, data = PlotData_df)`

Then choose whether or not to show the fitted regression function / equation. You'll need two equations, one for males and the other for females. Because we choose to plug in coefficients / numbers, there is no alternative option. The instructions below will show you how to obtain them.

```## formatted coefficients
theta <- signif(fit\$coef, digits = 2)
# (Intercept)  Height  GenderMale  Height:GenderMale
#        4.42   -0.30       -1.01               0.54

## equation for Female:
eqn_Female <- paste0("Velocity = ", theta, " * Height + ", theta)
#  "Velocity = -0.30 * Height + 4.42"

## equation for Male:
eqn_Male <- paste0("Velocity = ", theta + theta, " * Height + ", theta + theta)
#  "Velocity = 0.24 * Height + 3.41"```

The slope for Male is theta + theta, while the intercept is theta + theta. You can familiarize yourself with ANOVA and contrast treatment for factor variables.

• 6,000 points

## How to get early stopping for lasso regression

I believe you're referring to regularization. In ...READ MORE

## How to plot support vectors for support vector regression?

The problem was solved after I improved ...READ MORE

## How to resolve heteroscedasticity in Multiple Linear Regression in R?

Try to use a different form of ...READ MORE

## How to get a regression summary in scikit-learn like R does?

In sklearn, there is no R type ...READ MORE

## R: Force regression coefficients to add up to 1

b1 + b2 = 1 Let us fit ...READ MORE

## Extract regression coefficient values

A quick rundown. These values are stored ...READ MORE

## Selecting only p-value and r.squared value from linear regression result

You can use the \$ symbol to ...READ MORE

## How to add regression line equation and R2 on graph?

Below is one solution: # GET EQUATION AND ...READ MORE