[R] Scaling variables to positive values using scale() or performing BoxCox on negative data

David Winsemius dwinsemius at comcast.net
Mon Nov 30 18:40:03 CET 2009


On Nov 30, 2009, at 11:47 AM, Henry Thorogood wrote:

> The scale function seems to have tackled the skew, just looking at the
> boxplots for the data.
>
> The boxcox function I'm using is boxcox(), from MASS.

I'm puzzled. When I look at the boxcox function in MASS it says:

"Arguments
object     a formula or fitted model object. Currently only lm and aov  
objects are handled."

And I did not see anything about a regression model in what you wrote.

> I've looked through
> the help page, but I don't think (from what I can see) there's a way  
> to make
> the boxcox function handle the negative values, unlike say the b.c  
> function
> (from car, I think), which has a 'start' argument.

That was the package I was thinking you might be using.
>
> How would I add, say, a constant c to each piece of data? Whilst I  
> think I
> understand the stats, I'm pretty terrible at manipulating R, as I've  
> only
> been using it for a few days!

if the object is "obj" then adding a constant, "ccc", is as simple as:

shift_obj <- obj + ccc

You really should go back to your introductory text now and be more  
systematic in pursuit of learning the language . This is extremely  
basic stuff so you are probably not at the stage to be learning by  
experimentation. Get the basics first.

(Notice that I don't use "c" as the name of an object. It is a crucial  
function in R and you will tie your brain in knots if you have both  
meanings of "c" floating around.)

>
> Thanks again,
>
> Henry
>
> 2009/11/30 David Winsemius <dwinsemius at comcast.net>
>
>>
>> On Nov 30, 2009, at 11:02 AM, Henry Thorogood wrote:
>>
>> Hi,
>>>
>>> I'm doing some work with linear models, and I've scaled my data  
>>> using the
>>> scale(dataset) function. This was great at removing the skew, but  
>>> I now
>>> can't perform the Box Cox transformation on the data set (using the
>>> boxcox(dataset) function), as the scaling has returned negative  
>>> values.
>>>
>>
>> Scaling (at least that using the default approach with that function)
>> should not "remove" skewness.
>>
>>
>>
>>> So my question is: how can I get the scale function to return a  
>>> positive
>>> set
>>> of data (so I can use Box-Cox),
>>>
>>
>> You could shift the scaled values to the right.
>>
>>
>> or how can I get the boxcox function to
>>> handle negative values.
>>>
>>
>> Which boxcox function? And have you looked at all of its available
>> parameters?
>>
>> --
>> David Winsemius, MD
>> Heritage Laboratories
>> West Hartford, CT
>>
>>
>
> 	[[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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list