Skip to content

Commit 0320858

Browse files
Proof reading: logistic regression
1 parent 1a218c8 commit 0320858

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

individual_modules/regression_analysis_with_R/logistic_regression.ipynb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"\n",
9494
"$$\\sigma(t) = \\frac{e^t}{e^t+1}$$\n",
9595
"\n",
96-
"We can visualise the transform between the right hand side and the left hand side of the equation in the graph below"
96+
"We can visualise the transform between the right-hand side and the left-hand side of the equation in the graph below"
9797
]
9898
},
9999
{
@@ -135,9 +135,9 @@
135135
"\n",
136136
"$$ln(odds) = ln(\\frac{p}{(1-p)}) = \\beta_0 + \\beta_1*x$$\n",
137137
"\n",
138-
"We are no longer in the class of linear regression, we are in a more general class of generalised linear models. These permit a more varied number of regression models with different types of outcomes.They use a link function to transform from the unbounded prediction on the right hand side to the properties of the outcome variable on the left hand side. For logistic regression the link function is the logistic function. This means we also need a new R function, `glm()` to fit them. \n",
138+
"We are no longer in the class of linear regression, we are in a more general class of generalised linear models. These permit a more varied number of regression models with different types of outcomes.They use a link function to transform from the unbounded prediction on the right-hand side to the properties of the outcome variable on the left-hand side. For logistic regression, the link function is the logistic function. This means we also need a new R function, `glm()` to fit them. \n",
139139
"\n",
140-
"Let's look at an example we are going to predict Type II diabetes status from bmi."
140+
"Let's look at an example. We are going to predict Type II diabetes status from BMI."
141141
]
142142
},
143143
{
@@ -225,7 +225,7 @@
225225
"id": "537e3273-ce41-415d-96cc-641afa3adedf",
226226
"metadata": {},
227227
"source": [
228-
"We can see that the odds ratios is `r signif(exp(coef(model.log))[\"bmi\"], 3)` which can be reported as for a 1 unit increase of BMI an individual is `r signif(exp(coef(model.log))[\"bmi\"], 3)` times more likely to develop Type 2 Diabetes. This effect is not very big!\n",
228+
"We can see that the odds ratios is `r signif(exp(coef(model.log))[\"bmi\"], 3)` which can be reported as for a 1 unit increase of BMI an individual is `r signif(exp(coef(model.log))[\"bmi\"], 3)` times more likely to develop Type II Diabetes. This effect is not very big!\n",
229229
"\n",
230230
"Significance testing is conceptually the same as for linear regression, whereby each regression coefficient (i.e. log odds ratio) is tested to see if it is non-zero. It differs though how it is calculated. As we are no longer able to derive an exact solution, we have to use an iterative method to find the best estimates. This means you sometimes might get warnings that your model failed to converge. This means that the algorithm was not able to settle on an appropriate solution for the best regression coefficients and the result should be treated with caution. Typically, this is due to not enough data or trying to fit too many predictor variables simultaneously or a poor choice of model between X and Y. \n",
231231
"\n",
@@ -303,15 +303,15 @@
303303
"id": "f3267dd2-dd18-4e27-bef5-928fc8ee4a8c",
304304
"metadata": {},
305305
"source": [
306-
"We can use the confidence interval to determine whether our estimated regression coefficient has a non-zero effect, by whether it contains the null value. For example at a significance level of $\\alpha = 0.05$, if the estimated coefficient is significantly non zero (i.e. $p-value < 0.05$) then the 100(1-$\\alpha$) = 95% confidence interval will not contain 0. The null value for the log(OR) is 0, and the null value for the OR is 1. Therefore, if we don't convert our confidence interval to the correct units we may draw the wrong conclusion. \n",
306+
"We can use the confidence interval to determine whether our estimated regression coefficient has a non-zero effect, by whether it contains the null value. For example, at a significance level of $\\alpha = 0.05$, if the estimated coefficient is significantly non-zero (i.e. $p-value < 0.05$) then the 100(1-$\\alpha$) = 95% confidence interval will not contain 0. The null value for the log(OR) is 0, and the null value for the OR is 1. Therefore, if we don't convert our confidence interval to the correct units, we may draw the wrong conclusion. \n",
307307
"\n",
308308
"Logistic regression is all about appropriately handling the non-continuous outcome variable. The predictor variables can be as complex as your dataset can handle and include categorical variables etc. in the same way as we described for linear regression. \n",
309309
"\n",
310310
"Let's practise some examples:\n",
311311
"\n",
312312
"## Logistic Regression with Multiple Predictor Variables Exercise\n",
313313
"\n",
314-
"*Fit a logistic regression model to test for an association between age and type 2 diabetes status*\n"
314+
"*Fit a logistic regression model to test for an association between age and type II diabetes status*\n"
315315
]
316316
},
317317
{
@@ -1365,7 +1365,7 @@
13651365
"id": "d896fb6c-f2ad-4152-9244-a3f51c941649",
13661366
"metadata": {},
13671367
"source": [
1368-
"*Fit a logistic regression model to test for an association between age, alcohol units and exercise time and type 2 diabetes status*"
1368+
"*Fit a logistic regression model to test for an association between age, alcohol units and exercise time and type II diabetes status*"
13691369
]
13701370
},
13711371
{
@@ -2440,7 +2440,7 @@
24402440
"id": "58f0efbf-af31-4ffe-8945-92f41ced9afb",
24412441
"metadata": {},
24422442
"source": [
2443-
"*Fit a logistic regression model to test for an association between socioeconomic status and type 2 diabetes status, controlling for age and bmi.*"
2443+
"*Fit a logistic regression model to test for an association between socioeconomic status and type II diabetes status, controlling for age and BMI.*"
24442444
]
24452445
},
24462446
{
@@ -3512,13 +3512,13 @@
35123512
"source": [
35133513
"\n",
35143514
"\n",
3515-
"You may have noticed in the last example above that while the ANOVA for the ethnicity variable was significant neither of the two dummy variables were significantly associated at P < 0.05. The `ethnicityEuropean` showed a trend for significance with P~0.05. This happens sometimes becuase when you use an ANOVA to test for the joint effect of both dummy variables, you are using a 2 degree of freedom test (see third column in the ANOVA output), while in the tests for the individual coefficients you are using a 1 degree of freedom test. Mathematically the threshold for a two degree of freedom test is slightly lower to be significant. You could think of this as rather than needing a really strong effect in one variable, a small effect, but in both variables would be meaningful. In reality these results are not contradicting each other, its just a chance thing related to the fact that we have used a hard threshold to determine significance. Where you only just have enough statitstica power to detect an effect, it is chance whether it falls just above the trheshold or just below. \n",
3515+
"You may have noticed in the last example above that while the ANOVA for the ethnicity variable was significant, neither of the two dummy variables were significantly associated at P < 0.05. The `ethnicityEuropean` showed a trend for significance with P~0.05. This happens sometimes because when you use an ANOVA to test for the joint effect of both dummy variables, you are using a 2 degree of freedom test (see third column in the ANOVA output), while in the tests for the individual coefficients you are using a 1 degree of freedom test. Mathematically the threshold for a two degree of freedom test is slightly lower to be significant. You could think of this as rather than needing a really strong effect in one variable, a small effect but in both variables would be meaningful. In reality, these results are not contradicting each other, it's just a chance thing related to the fact that we have used a hard threshold to determine significance. Where you only just have enough statitstical power to detect an effect, it is chance whether it falls just above the threshold or just below. \n",
35163516
"\n",
35173517
"## Predictions with the Logistic Regression Model\n",
35183518
"\n",
3519-
"We are going to make some predictions from a logiistic regression model to show how the model goes from a weighted sum of prediction variables to the binary outcome variable. \n",
3519+
"We are going to make some predictions from a logistic regression model to show how the model goes from a weighted sum of prediction variables to the binary outcome variable. \n",
35203520
"\n",
3521-
"Let's revist the example of prediction type 2 diabetes as a function of alcohol units and exercise hours. First we need to fit the model.\n"
3521+
"Let's revisit the example of predicting type II diabetes as a function of alcohol units and exercise hours. First, we need to fit the model.\n"
35223522
]
35233523
},
35243524
{
@@ -3550,7 +3550,7 @@
35503550
"id": "dc5114f8-dd4a-47c8-be6a-1324e72d79ad",
35513551
"metadata": {},
35523552
"source": [
3553-
"Using our estimated regression coefficients we can write our fitted regression model as"
3553+
"Using our estimated regression coefficients we can write our fitted regression model as `r logEq`."
35543554
]
35553555
},
35563556
{
@@ -3570,9 +3570,9 @@
35703570
"id": "b91a9b68-eeca-4a3b-850d-7f428418b019",
35713571
"metadata": {},
35723572
"source": [
3573-
"`r logEq`.\n",
35743573
"\n",
3575-
"Let's say we have a new observation we want to make a prediction for, we know that they exercise for on average 4 hours a week and consume 10 units of alcohol per week. We can input these values into our equation to estimate the log odds of the this individual having type 2 diabetes. \n"
3574+
"\n",
3575+
"Let's say we have a new observation we want to make a prediction for, we know that they exercise for on average 4 hours a week and consume 10 units of alcohol per week. We can input these values into our equation to estimate the log odds of this individual having type II diabetes. \n"
35763576
]
35773577
},
35783578
{

individual_modules/regression_analysis_with_R/questions/logistic_regression_3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
]
1717
},
1818
{
19-
"question": "Considering the estimated regression coefficients for the two binary variabels for ethnicty, which of the following statements are correct? Ignore the P-values we are just interested in interpeting the regression coefficients. Select all that apply.",
19+
"question": "Considering the estimated regression coefficients for the two binary variables for ethnicity, which of the following statements are correct? Ignore the P-values we are just interested in interpreting the regression coefficients. Select all that apply.",
2020
"type": "many_choice",
2121
"answers": [
2222
{

individual_modules/regression_analysis_with_R/questions/summary_logistic_regression.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "many_choice",
55
"answers": [
66
{
7-
"answer": "TO predict a continuous outcome",
7+
"answer": "To predict a continuous outcome",
88
"correct": false,
99
"feedback": "Incorrect"
1010
},

0 commit comments

Comments
 (0)