回归使输入变量之一产生误差。“对比度只能应用于具有2个或多个级别的因数”。 [英] Regression gives error on one of the input variables "contrasts can be applied only to factors with 2 or more levels"

查看:85
本文介绍了回归使输入变量之一产生误差。“对比度只能应用于具有2个或多个级别的因数”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中使用大量输入变量运行logit回归。

  newlogit<-glm(install。〜SIZES + GROSSCONSUMPTION .... + 
NETTCONSUMPTION .... 。+ NETTGENERATION ....... +
GROSSGENERATION .... +变量。+固定+
Cost.of.gross.cons + Cost.of.net.cons +节约成本+
代增+总节省额+系统成本+
回报+自我消费+总消费量太阳能+
所有者占用+邮政编码+郊区+市场。渗透+
X..green.vote,数据= newdata,家庭=二项式)

我收到此错误:


对比错误<-(tmp,value = contr.funs [1 + isOF [nn] ]):
对比只能应用于具有2个或更多水平的因子


请问为什么发生此错误,是否有办法运行此回归?


解决方案

它反对您的一个变量(如gvrocha所说);您可能只有一个水平或一个字符串。



一个快速跟踪有问题的变量的技巧是进行区间平分和增加/减少col索引,直到触发错误为止。



最好使用数字(列索引)界面进行glm( glm(data [,'安装。']〜data [,2:40]),请参见[1])



而不是公式界面 glm(install。〜var1 + var2 + ...



[1] 在R中创建动态公式?


I am running a logit regression in R with a large number of input variables.

newlogit <- glm(install. ~ SIZES + GROSSCONSUMPTION.... + 
                NETTCONSUMPTION..... + NETTGENERATION....... + 
                GROSSGENERATION.... + Variable. + Fixed + 
                Cost.of.gross.cons + Cost.of.net.cons + Cons.savings + 
                generation.gains + Total.savings + Cost.of.system + 
                Payback + Self.consumption + Total.consumption.as.solar + 
                Owner.occupied + postcode + Suburb + Market.penetration + 
                X..green.vote, data = newdata, family = "binomial")

I am getting this error:

Error in contrasts<-(tmp, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

Would you please be able to advise why this error is occurring and if there is a way to run this regression?

解决方案

It objects to one of your variables (as gvrocha said); you might have a factor with only one level, or a string.

A tip to quickly track down the offending variable(s) is to do interval bisection and increase/decrease the col indices till you trigger the error.

Best to use the numerical (column-index) interface to glm (glm(data[,'install.'] ~ data[,2:40]), see [1])

rather than the formula interface glm(install. ~ var1 + var2 + ...:

[1] Dynamic formula creation in R?

这篇关于回归使输入变量之一产生误差。“对比度只能应用于具有2个或多个级别的因数”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆