[R] lm(y ~ group/x ) + predict.lm(...,type=terms)
Hi, all I am trying to figure out the computation result for predict.lm(...,type=terms) when the original fitting model has a nesting term, lm(y ~ group/x ). A example, set.seed(731) group - factor(rep(1:2, 200)) x - rnorm(400) fun1 - function(x) -3*x+8 fun2 - function(x) 15*x-18 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400) mod1 - lm(y ~ group/(x-1) ) # without intercetp mod2 - lm(y ~ group/x ) # with intercetp #data to predict new - data.frame(x=rep(0:2,each=2), + group=factor(rep(1:2,3))) new x group 1 0 1 2 0 2 3 1 1 4 1 2 5 2 1 6 2 2 coef(mod1) # checking coefficients, both make sense to me. group1 group2 group1:x group2:x 7.864981 -18.098424 -2.963931 15.051449 coef(mod2) (Intercept) group2group1:xgroup2:x 7.864981 -25.963405 -2.963931 15.051449 predict(mod1, new,type = c(response)) # two response type predictions are the same, make sense to me. 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod2, new,type = c(response)) 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod1, new,type = c(terms)) # make sense to me group group:x 1 7.864981 0.00 2 -18.098424 0.00 3 7.864981 -2.963931 4 -18.098424 15.051449 5 7.864981 -5.927861 6 -18.098424 30.102898 attr(,constant) [1] 0 # I want to know the computation process for group:x below??? this is what I am interested in predict(mod2, new,type = c(terms)) groupgroup:x 1 12.9817 0.5209069 2 -12.9817 0.5209069 3 12.9817 -2.4430237 4 -12.9817 15.5723560 5 12.9817 -5.4069544 6 -12.9817 30.6238052 attr(,constant) [1] -5.637629 Thanks in advance Xing __ R-help@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.
[R] lm(y ~ group/x ) + predict.lm(...,type=terms)
Hi, all I am trying to figure out the computation result for predict.lm(...,type=terms) when the original fitting model has a nesting term, lm(y ~ group/x ). A example, set.seed(731) group - factor(rep(1:2, 200)) x - rnorm(400) fun1 - function(x) -3*x+8 fun2 - function(x) 15*x-18 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400) mod1 - lm(y ~ group/(x-1) ) # without intercetp mod2 - lm(y ~ group/x ) # with intercetp #data to predict new - data.frame(x=rep(0:2,each=2), + group=factor(rep(1:2,3))) new x group 1 0 1 2 0 2 3 1 1 4 1 2 5 2 1 6 2 2 coef(mod1) # checking coefficients, both make sense to me. group1 group2 group1:x group2:x 7.864981 -18.098424 -2.963931 15.051449 coef(mod2) (Intercept) group2group1:xgroup2:x 7.864981 -25.963405 -2.963931 15.051449 predict(mod1, new,type = c(response)) # two response type predictions are the same, make sense to me. 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod2, new,type = c(response)) 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod1, new,type = c(terms)) # make sense to me group group:x 1 7.864981 0.00 2 -18.098424 0.00 3 7.864981 -2.963931 4 -18.098424 15.051449 5 7.864981 -5.927861 6 -18.098424 30.102898 attr(,constant) [1] 0 # I want to know the computation process for group:x below??? this is what I am interested in predict(mod2, new,type = c(terms)) groupgroup:x 1 12.9817 0.5209069 2 -12.9817 0.5209069 3 12.9817 -2.4430237 4 -12.9817 15.5723560 5 12.9817 -5.4069544 6 -12.9817 30.6238052 attr(,constant) [1] -5.637629 Thanks in advance Xing [[alternative HTML version deleted]] __ R-help@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.
[R] lm(y ~ group/x ) + predict.lm(...,type=terms)
Hi, all I am trying to figure out the computation result for predict.lm(...,type=terms) when the original fitting model has a nesting term, lm(y ~ group/x ). A example, set.seed(731) group - factor(rep(1:2, 200)) x - rnorm(400) fun1 - function(x) -3*x+8 fun2 - function(x) 15*x-18 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400) mod1 - lm(y ~ group/(x-1) ) # without intercetp mod2 - lm(y ~ group/x ) # with intercetp #data to predict new - data.frame(x=rep(0:2,each=2), + group=factor(rep(1:2,3))) new x group 1 0 1 2 0 2 3 1 1 4 1 2 5 2 1 6 2 2 coef(mod1) # checking coefficients, both make sense to me. group1 group2 group1:x group2:x 7.864981 -18.098424 -2.963931 15.051449 coef(mod2) (Intercept) group2group1:xgroup2:x 7.864981 -25.963405 -2.963931 15.051449 predict(mod1, new,type = c(response)) # two response type predictions are the same, make sense to me. 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod2, new,type = c(response)) 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod1, new,type = c(terms)) # make sense to me group group:x 1 7.864981 0.00 2 -18.098424 0.00 3 7.864981 -2.963931 4 -18.098424 15.051449 5 7.864981 -5.927861 6 -18.098424 30.102898 attr(,constant) [1] 0 # I want to know the computation process for group:x below??? this is what I am interested in predict(mod2, new,type = c(terms)) groupgroup:x 1 12.9817 0.5209069 2 -12.9817 0.5209069 3 12.9817 -2.4430237 4 -12.9817 15.5723560 5 12.9817 -5.4069544 6 -12.9817 30.6238052 attr(,constant) [1] -5.637629 Thanks in advance Xing [[alternative HTML version deleted]] __ R-help@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.
Re: [R] lm(y ~ group/x ) + predict.lm(...,type=terms)
Please see the posting guide: posting 3 times only reduces your chance of an informative answer (as does posting in HTML). Your posting is too vague for others to know what it is you do not understand. R is Open Source: please read the sources for the definitive answer to the 'know the computation process' query. If (as I suspect) your difficulty is rather with interpreting terms in formulae, study chapter 6 of MASS (Venables Ripley, 2002). On 18/01/2014 22:03, Xing Zhao wrote: Hi, all I am trying to figure out the computation result for predict.lm(...,type=terms) when the original fitting model has a nesting term, lm(y ~ group/x ). 'nested' A example, set.seed(731) group - factor(rep(1:2, 200)) x - rnorm(400) fun1 - function(x) -3*x+8 fun2 - function(x) 15*x-18 y - (group==1)*fun1(x)+(group==2)*fun2(x) + rnorm(400) mod1 - lm(y ~ group/(x-1) ) # without intercetp mod2 - lm(y ~ group/x ) # with intercetp #data to predict new - data.frame(x=rep(0:2,each=2), + group=factor(rep(1:2,3))) new x group 1 0 1 2 0 2 3 1 1 4 1 2 5 2 1 6 2 2 coef(mod1) # checking coefficients, both make sense to me. group1 group2 group1:x group2:x 7.864981 -18.098424 -2.963931 15.051449 coef(mod2) (Intercept) group2group1:xgroup2:x 7.864981 -25.963405 -2.963931 15.051449 predict(mod1, new,type = c(response)) # two response type predictions are the same, make sense to me. 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod2, new,type = c(response)) 1 2 3 4 5 6 7.864981 -18.098424 4.901050 -3.046975 1.937120 12.004474 predict(mod1, new,type = c(terms)) # make sense to me group group:x 1 7.864981 0.00 2 -18.098424 0.00 3 7.864981 -2.963931 4 -18.098424 15.051449 5 7.864981 -5.927861 6 -18.098424 30.102898 attr(,constant) [1] 0 # I want to know the computation process for group:x below??? this is what I am interested in predict(mod2, new,type = c(terms)) groupgroup:x 1 12.9817 0.5209069 2 -12.9817 0.5209069 3 12.9817 -2.4430237 4 -12.9817 15.5723560 5 12.9817 -5.4069544 6 -12.9817 30.6238052 attr(,constant) [1] -5.637629 Thanks in advance Xing [[alternative HTML version deleted]] __ R-help@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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] lm on group
You can guess by looking at class(g). It is a factor. It is NOT regressing on the mean of g (i.e. 2.5 and 7.5) and you could have changed g from (0,5] and (5,10] to A and B with the same results. Read some books or help(lm) to get an idea of what the outputs mean. Regards, Adai newbieR wrote: Hi all, I have a quick question about lm on group, say I have: x - 1:10 y - x*3 buckets - seq(0, 10, by=5) g - cut(x, buckets) summary(lm(y ~ g - 1)) Coefficients: Estimate Std. Error t value Pr(|t|) g(0,5] 9.000 2.121 4.243 0.00283 ** g(5,10] 24.000 2.121 11.314 3.35e-06 *** What is it doing exactly? I guess the estimate is the mean of the y's in each group. How about other stats.. what do they exactly mean when we do lm on groups? Thanks a lot! __ R-help@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.
[R] lm on group
Hi all, I have a quick question about lm on group, say I have: x - 1:10 y - x*3 buckets - seq(0, 10, by=5) g - cut(x, buckets) summary(lm(y ~ g - 1)) Coefficients: Estimate Std. Error t value Pr(|t|) g(0,5] 9.000 2.121 4.243 0.00283 ** g(5,10] 24.000 2.121 11.314 3.35e-06 *** What is it doing exactly? I guess the estimate is the mean of the y's in each group. How about other stats.. what do they exactly mean when we do lm on groups? Thanks a lot! -- View this message in context: http://n4.nabble.com/lm-on-group-tp1107220p1107220.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.