简体   繁体   English

R:通过glm应用logit模型时,stats包如何处理字符向量?

[英]R: How does the stats package handle character vectors when applying a logit model through glm?

I am running a logistic regression and I am noticing that each unique character string in my vector is receiving its own parameter. 我正在进行逻辑回归,我注意到向量中的每个唯一字符串都接收到自己的参数。 Is R optimizing the prediction on the outcome variable based each collection of unique values within the vector? R是否基于矢量内唯一值的每个集合来优化对结果变量的预测?

sorry. 抱歉。 A little new to stack overflow. 堆栈溢出有点新。

library(stats)
df = as.data.frame( matrix(c("a","a","b","c","c","b","a","a","b","b","c",1,0,0,0,1,0,1,1,0,1,0,1,0,100,10,8,3,5,6,13,10,4,"SF","CHI","NY","NY","SF","SF","CHI","CHI","SF","CHI","NY"), ncol = 4))
colnames(df) = c("letter","number1","number2","city")
df$letter = as.factor(df$letter)
df$city = as.factor(df$city)
df$number1 = as.numeric(df$number1)
df$number2 = as.numeric(df$number2)

glm(number1 ~ .,data=df)

#Call:  glm(formula = number1 ~ ., data = df)

#Coefficients:
#  (Intercept)      letterb      letterc      number2       cityNY       citySF  
#1.57191     -0.25227     -0.01424      0.04593     -0.69269     -0.20634  

#Degrees of Freedom: 10 Total (i.e. Null);  5 Residual
#Null Deviance:     2.727 
#Residual Deviance: 1.35    AIC: 22.14

How is the logit treating city? Logit如何治疗城市?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM