Skip to content

Commit

Permalink
Merge pull request #343 from Nixon-hk/Fix_coefficient
Browse files Browse the repository at this point in the history
Fix coefficient
  • Loading branch information
statasaurus authored Oct 21, 2024
2 parents ccc06bf + f717a47 commit 2caa877
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions R/linear-regression.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ head(htwt)

### Regression Analysis

Next, we fit a regression model, representing the relationships between gender, age, height and the interaction variable created in the datastep above. We again use a where statement to restrict the analysis to those who are less than or equal to 19 years old. We use the clb option to get a 95% confidence interval for each of the parameters in the model. The model that we are fitting is ***height = b0 + b1 x female + b2 x age + b3 x fem_age + e***
Next, we fit a regression model, representing the relationships between gender, age, height and the interaction variable created in the datastep above. We again use a where statement to restrict the analysis to those who are less than or equal to 19 years old. We use the clb option to get a 95% confidence interval for each of the parameters in the model. The model that we are fitting is $height = b_0 + b_1\times female + b_2\times age + b_3\times fem\_age + e$

```{r}
regression<-lm(HEIGHT~female+AGE+fem_age, data=htwt, AGE<=19)
summary(regression)
b0=round(regression$coefficients[1],4)
b1=round(regression$coefficients[2],4)
b2=round(regression$coefficients[3],4)
b3=round(regression$coefficients[4],4)
```

From the coefficients table b0,b1,b2,b3 are estimated as b0=28.88 b1=13.61 b2=2.03 b3=-0.92942
From the coefficients table b0,b1,b2,b3 are estimated as b0=`r b0` b1=`r b1` b2=`r b2` b3=`r b3`


The resulting regression model for height, age and gender based on the available data is ***height=28.8828 + 13.6123 x female + 2.0313 x age -0.9294 x fem_age***
The resulting regression model for height, age and gender based on the available data is $height= `r b0` + `r b1`\times female + `r b2`\times age `r b3`\times fem\_age$

0 comments on commit 2caa877

Please sign in to comment.