Greetings to every body. we know that for linear regression: two-parameter fitting in R: (for a and b as slope and intercept) [a] for y=ax+b type models we use: lm(y~x) [b] for y=ax type models we use: lm(y~0+x) => forced to pass through origin Now I have question: what about y=b fitting? is there any model to force or impose the ax to be zero Let say x <- c(1,2,3,4,5,6,7,8,9) y <- c( 0.853,0.852, 0.854, 0.858, 0.862, 0.856, 0.858, 0.857, 0.863) plot(y~x, xlim=c(0,10), ylim=c(0,1)) abline(lm(y~x),col="blue") # this doesn't give exact horizontal but slightly inclined. or is it as simple as, just find the intercept using the lm(y~x) , then abline(h=intercept,col="red") ? any comment or advice is greatly appreciated ;) [[alternative HTML version deleted]]
Hello, Try ?mean abline(h = mean(y), col = "blue") Hope this helps, Rui Barradas Em 03-07-2013 15:07, Birdada Simret escreveu:> Greetings to every body. > > we know that for linear regression: two-parameter fitting in R: (for a and > b as slope and intercept) > > [a] for y=ax+b type models we use: lm(y~x) > [b] for y=ax type models we use: lm(y~0+x) => forced to pass through > origin > > Now I have question: what about y=b fitting? is there any model to > force or impose the ax to be zero > > Let say > > x <- c(1,2,3,4,5,6,7,8,9) > y <- c( 0.853,0.852, 0.854, 0.858, 0.862, 0.856, 0.858, 0.857, 0.863) > plot(y~x, xlim=c(0,10), ylim=c(0,1)) > abline(lm(y~x),col="blue") # this doesn't give exact horizontal but > slightly inclined. > > or is it as simple as, just find the intercept using the lm(y~x) , then > abline(h=intercept,col="red") ? > > any comment or advice is greatly appreciated ;) > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
> Now I have question: what about y=b fitting? is there any model to > force or impose the ax to be zeroRui Barradas has answered correctly for a simple lm case. You can also do lm(y~1) to obtain an estimated mean. That formulation happens to be quite useful if you are interested in a purely random-effects model* fitted using, say, lme, though you won't generally get a simple mean for unbalanced data in such a case. S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}