Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

lm - Datatype for linear model in 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

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  

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

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...