I have a project. And within this project, i make basic lineer regression analysis. My response variable is preference between Apple and Huawei; explanatory variable is people's age who makes a choice.
But there is a problem. One of the variables of data is not numerical(It's character: Apple and Huawei). How can I make the lineer regression ?
Linear regression is designed for response variables that are continuous, they can take on a large, if not infinite, number of values. Binary response variables, either/or can only take one one of two, coded as 0/1.
Logistic regression is designed for discrete variables. The most common type, and the one you are using is binomial. The R syntax to deal with this class of problem is
fit <- glm(choice ~ age, type = 'binomial')
You get somewhat different diagnostics. High p-values will tell you right away if there is a lack of association, but low p-values require goodness-of-fit analysis.
Firstly, thanks for your help. But it doesn't work.
Now i'm gonna try to explain the probem by using some screenshots.
This is my dataset.
Here, i tried to make a lineer model.
And it has failed. It says "Tercih"(preference) not found. I wonder, one of the variables of data is not numerical and that's why it has failed ? If the reason is this, what can i do ? How can i solve the problem ?
And additionally, as first i changed the names of the response variable. (For Apple:0 for Huawei :1) then when i try to make regression analysis in R Commander, i got some values (like p-value, R squared,....). Are these values are reliable ? I'm loading those screenshots.
My blunder; I didn't include the name of the data frame in the argument to glm
fit <- glm(data = veritchihyas, Tercih ~ Yas., family = binomial)
(and I shouldn't have quoted the argument to family.
What the lm
model is telling you is that age is a slightly worse predictor than flipping a coin.
Thank you so much for your help. But i suppose i won't be able to get the correct outputs. Because as you see :
The spreader plot is this. And correspondingly i cannot make the lineer regression(abline of this plot cannot be draw ).
Yes, this is exactly what you see with linear regression applied to binary data. I put my notes from the first chapter of Applied Logistic Regression by Hosmer, Lameshow and Sturdivant at https://s3-us-west-2.amazonaws.com/tuva/PlotLogisticData.pdf Don't worry about the equations. Look at the data tables. The upper plot show linear regression and the lower plot shows logistic regression after binning the data.
Thanks for your help!
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.