# Logistic regression and prediction

I'm following this tutorial to fit a logistic regression model on to my data which has a binary response. I've understood the reasoning behind each step, apart from why the author checks the first 5 probabilities within glm.probs and observes they are close to 50% and so sets glm.pred to the following:

glm.pred <- ifelse(glm.probs > 0.5, "Up", "Down")


Lets say you observe the first 5 or even take the mean of probabilities and you obtain a value of 0.25. Does that now mean you set glm.pred to:

glm.pred <- ifelse(glm.probs > 0.25, "Up", "Down")


Also another question I have is regarding the removal of variables. From my understanding, a variable with a p-value > 0.05 means we cannot conclude the effect the variable has on the model. Some say you shouldn't remove the variable itself as you lose important information. So how do we then try to improve the model?

• Just as the significance level, the break value used for dichotomisation is not dependent on your data. In fact, one could argue that you shouldn't even do this step. Anyway, this is off-topic here. – Roland Mar 29 '19 at 11:32
• Would it not produce a higher classification rate and solve the problem of overfitting by testing the model with new data? – Ali Mar 29 '19 at 11:34
• What you asking is theory, rather than code. Try stackexchange instead, and search for logistic regression probability cut-off points, there you will find the answers to these questions. – Felipe Alvarenga Mar 29 '19 at 11:39

When the author does glm.pred <- ifelse(glm.probs > 0.5, "Up", "Down"), what they are doing implicitly is saying that if the model returns a probability greater than 50%, then assume that the "Up" event will occur. Thus, your prediction will be "Up". If the probability is less than or equal to 0.5, predict "Down".
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7210633158683777, "perplexity": 875.6522210585699}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-05/segments/1579250606696.26/warc/CC-MAIN-20200122042145-20200122071145-00528.warc.gz"}