Hi all I was playing with termplot(), and came across what appears to be an inconsistency. It would appreciate if someone could enlighten me:> # First, generate some data: > y <- rnorm(100) > x <- runif(length(y),1,2)> # Now find the log of x: > logx <- log(x) > > # Now fit two models that are exactly the same, but specified differently: > m1 <- lm(y~log(x)) # Using log in the call > m2 <- lm(y~logx) # Using the variable logx > > # The two termplots() are different: > par(mfrow=c(1,2)) > termplot(m1) > termplot(m2)I see two models that are identical, but produce different termplot()s. In both cases, the independent variable is log(x), but is just specified differently. If this is intended, what is the logic? Or am I missing something? Thanks. P.> sessionInfo()R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 locale: [1] en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base Peter Dunn: Biostatistician (Room T4.12) School of Health and Sport Science Faculty of Science, Health and Education ML-34 University of the Sunshine Coast, Locked Bag 4 Maroochydore DC Qld 4558 Tel: +61 7 5456 5085 Fax: +61 7 5430 2896 Email: pdunn2 at usc.edu.au www.usc.edu.au CRICOS Provider Number: 01595D This communication is intended for the recipient only and should not be forwarded, distributed or otherwise read by others without express permission. The views expressed in this email are not necessarily those of the University of the Sunshine Coast. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On 27/08/10 01.10, Peter Dunn wrote:> Hi all > > I was playing with termplot(), and came across what appears to be an > inconsistency. > > It would appreciate if someone could enlighten me: > >> # First, generate some data: y<- rnorm(100) x<- runif(length(y),1,2) > >> # Now find the log of x: logx<- log(x) >> >> # Now fit two models that are exactly the same, but specified differently: >> m1<- lm(y~log(x)) # Using log in the call m2<- lm(y~logx) # Using the >> variable logx >> >> # The two termplots() are different: par(mfrow=c(1,2)) termplot(m1) >> termplot(m2) > > > I see two models that are identical, but produce different termplot()s. In > both cases, the independent variable is log(x), but is just specified > differently. > > If this is intended, what is the logic? Or am I missing something?I believe it is intended, and quite as expected. The plot is against the term variable on its original scale - not the transformed scale. - Niels> > Thanks. > > P. > >> sessionInfo() > R version 2.11.1 (2010-05-31) x86_64-apple-darwin9.8.0 > > locale: [1] en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8 > > attached base packages: [1] stats graphics grDevices utils datasets > methods base > > > Peter Dunn: Biostatistician (Room T4.12) School of Health and Sport Science > Faculty of Science, Health and Education ML-34 University of the Sunshine > Coast, Locked Bag 4 Maroochydore DC Qld 4558 > > Tel: +61 7 5456 5085 Fax: +61 7 5430 2896 Email: pdunn2 at usc.edu.au > www.usc.edu.au > > CRICOS Provider Number: 01595D This communication is intended for the > recipient only and should not be forwarded, distributed or otherwise read by > others without express permission. The views expressed in this email are not > necessarily those of the University of the Sunshine Coast. >-- Niels Richard Hansen Web: www.math.ku.dk/~richard Associate Professor Email: Niels.R.Hansen at math.ku.dk Department of Mathematical Sciences nielsrichardhansen at gmail.com University of Copenhagen Skype: nielsrichardhansen.dk Universitetsparken 5 Phone: +45 353 20783 (office) 2100 Copenhagen ? +45 2859 0765 (mobile) Denmark
Hi> the two models are identical because of having the same independent > variable and dependent variable.they produce different termplot()s because > of they base on different variables,one is x,the other is logx.see the > lateral axis.Sure; this is all obvious from the code and the plots. But my question is *why* two fundamentally identical models produce different termplot()s? As the original post asks: If this is intended, what is the logic? Or am I missing something? Let me place explain further. Suppose I try this m1 <- lm(y~x) termplot(m1) and I see that there is a problem. So I decide to use log(x) as a predictor instead of x; I could do this one of two ways: logx <- log(x) m2 <- lm(y~logx) termplot(m2) m3 <- lm(y~log(x)) termplot(x3) In the first case, the new termplot() tells me the model looks good. In the second case, I output is the same as for termplot(m1) produced, and I don't really learn anything new. So the original questions remain: If this is intended, what is the logic? Or am I missing something? Perhaps I could add: How do I explain and justify this behaviour to someone? Thanks. P. Peter Dunn: Biostatistician (Room T4.12) School of Health and Sport Science Faculty of Science, Health and Education ML-34 University of the Sunshine Coast, Locked Bag 4 Maroochydore DC Qld 4558 Tel: +61 7 5456 5085 Fax: +61 7 5430 2896 Email: pdunn2 at usc.edu.au www.usc.edu.au CRICOS Provider Number: 01595D This communication is intended for the recipient only and should not be forwarded, distributed or otherwise read by others without express permission. The views expressed in this email are not necessarily those of the University of the Sunshine Coast. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On Aug 26, 2010, at 7:10 PM, Peter Dunn wrote:> Hi all > > I was playing with termplot(), and came across what appears to be an > inconsistency. > > It would appreciate if someone could enlighten me: > >> # First, generate some data: >> y <- rnorm(100) >> x <- runif(length(y),1,2) > >> # Now find the log of x: >> logx <- log(x) >> >> # Now fit two models that are exactly the same, but specified >> differently: >> m1 <- lm(y~log(x)) # Using log in the call >> m2 <- lm(y~logx) # Using the variable logx >> >> # The two termplots() are different: >> par(mfrow=c(1,2)) >> termplot(m1) >> termplot(m2) > > > I see two models that are identical, but produce different > termplot()s. In both cases, the independent variable is log(x), but > is just specified differently. > > If this is intended, what is the logic? Or am I missing something?I don't understand your complaint, The two termplots are both on the scale of the x-variable offered via the data argument (or in this case the formula argument) . In one case you offered it a transformed value; in the other you offered it an untransformed value and did the transformation within the lm function. termplot() "knew" or was able to discern what was going on in the second instance and had no way of "knowing" that a transformation had been done in the first. Where is the puzzle? (Forgive the anthropomophisation.) str(m1) . . . $ terms :Classes 'terms', 'formula' length 3 y ~ log(x) .. ..- attr(*, "variables")= language list(y, log(x)) .. ..- attr(*, "factors")= int [1:2, 1] 0 1 .. .. ..- attr(*, "dimnames")=List of 2 .. .. .. ..$ : chr [1:2] "y" "log(x)" .. .. .. ..$ : chr "log(x)" .. ..- attr(*, "term.labels")= chr "log(x)" -- David.> > Thanks. > > P. > >> sessionInfo() > R version 2.11.1 (2010-05-31) > x86_64-apple-darwin9.8.0 > > locale: > [1] en_AU.UTF-8/en_AU.UTF-8/C/C/en_AU.UTF-8/en_AU.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base >David Winsemius, MD West Hartford, CT
Seemingly Similar Threads
- Sweave output from print.summary.glm is too wide
- .NAME in .Fortran
- Error building package: LaTeX error when creating PDF version
- OT: Adding verbatim R code text into LaTeX documents: texttt; verb or url?
- termplot has problems with a single term (fix included) (PR#6679)