Hi, I am doing a political science project on voting behavior and trying to make a regression.
Model_2<-glm(gop_positive~dem_angry, data= my_data_set, family="binomial")
summary(Model_2)
plot(gop_positive, dem_angry, main = "Model Graphed",
xlab = "Is There Anything the Respondent Likes About Trump?",
ylab = "How Often does Respondent Feel Angry Towards Clinton?",
pch = 19)
I do this and get a bar graph that is accurate and I'm going to use it, but i need to get a regression and it's not doing that.
With only two variables, both binary, an correlation analysis is more appropriate. The logistic regression model being used yields a log likelihood of observing gop_positive in the presence of dem_negative and its plot presentation is quite different from ordinary least squares regression. I have an explainer here.
I admit I'm not sure why you're getting a bar graph instead of a scatter plot. But the main thing is that you plot command doesn't reference the regression Model_2.
You might want to post your data with dput() if it isn't too large.
you are quoting aesthetics; which is to say; not referring to the columns in your dataset but to the literal strings you are putting; you can either use aes_string() instead of aes() , or remove the quote marks, or replace the quote marks with backticks
I changed it to this:
ggplot(data= my_data_set, aes_string(gop_positive,dem_angry)) +
geom_point() +
geom_smooth(formula= y~x) +
theme_minimal()+
labs(x="Is There Anything the Respondent Likes About Trump?",
y= "How Often does Respondent Feel Angry Towards Clinton?",
title= "Relationship A") +
theme(plot.title = element_text(hjust=0.5, size=15, face = 'bold'))
and got this
Error in geom_point():
! Problem while computing aesthetics.
Error occurred in the 1st layer.
Caused by error in check_aesthetics():
! Aesthetics must be either length 1 or the same as the data (10)
Fix the following mappings: x and y
Run rlang::last_error() to see where the error occurred.
I put the quotes
Error in geom_point():
! Problem while computing aesthetics.
Error occurred in the 1st layer.
Caused by error in check_aesthetics():
! Aesthetics must be either length 1 or the same as the data (10)
Fix the following mappings: x and y
Run rlang::last_error() to see where the error occurred.
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
It would be good to follow @nirgrahamuk's (always) helpful advice about a reprex, etc. Remember that you can see all kinds of things that we can't see.
If the data set is large, then just post part of it.