[R] Using termplot() with transformations of x

David Winsemius dwinsemius at comcast.net
Mon Aug 30 03:25:58 CEST 2010


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



More information about the R-help mailing list