R中线性模型的数据类型 [英] Datatype for linear model in R

查看:146
本文介绍了R中线性模型的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分别从R分析中得到两个向量作为输出>

I get two vectors as output from R analysis, respectively>

 [1] "216" "217" "218" "219" "220" "221" "222" "223" "224" "225" "226"
 [1] 10014733 10014665 10014588 10014504 10014415 10014321 10014227 10014145 10014076 10014014 10013963

我们叫第一个a和第二个b.当我做lm(b〜a)时,它会抛出

Let's call the first one a and the second one b. When I do lm(b~a), it throws out

Call:
lm(formula = b ~ a)

Coefficients:
(Intercept)         a217         a218         a219         a220         a221         a222         a223         a224  
 10014733.4        -68.1       -145.8       -229.8       -318.5       -412.8       -506.4       -588.2       -657.4  
       a225         a226  
     -719.4       -770.8  

我只想拟合一条简单的线,可以用abline进一步绘制...这是数据结构问题吗?

I just want to fit a simple line, which can further be plotted with abline... Is this a data structure problem?

谢谢!

推荐答案

尝试在回归之前运行a <- as.numeric(as.character(a))a <- as.numeric(levels(a))[a].现在,a被设置为一个因子,并且回归处理方式是,将为a中的每个值分配其自己的系数,从而为您提供逐步的响应而不是一条直线.

Try running a <- as.numeric(as.character(a)) or a <- as.numeric(levels(a))[a] before the regression. Now a is set up as a factor, and the regression treats is in a way that each value in a is going to be assigned it's own coefficient, thus providing you with a stepwise response instead of a straight line.

这篇关于R中线性模型的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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