backtransform `scale()` for plotting
r
Solution
Take a look at:
attributes(d$s.x)
You can use the attributes to unscale:
d$s.x * attr(d$s.x, 'scaled:scale') + attr(d$s.x, 'scaled:center')
For example:
> x <- 1:10
> s.x <- scale(x)
> s.x
[,1]
[1,] -1.4863011
[2,] -1.1560120
[3,] -0.8257228
[4,] -0.4954337
[5,] -0.1651446
[6,] 0.1651446
[7,] 0.4954337
[8,] 0.8257228
[9,] 1.1560120
[10,] 1.4863011
attr(,"scaled:center")
[1] 5.5
attr(,"scaled:scale")
[1] 3.02765
> s.x * attr(s.x, 'scaled:scale') + attr(s.x, 'scaled:center')
[,1]
[1,] 1
[2,] 2
[3,] 3
[4,] 4
[5,] 5
[6,] 6
[7,] 7
[8,] 8
[9,] 9
[10,] 10
attr(,"scaled:center")
[1] 5.5
attr(,"scaled:scale")
[1] 3.02765
Problem
I have a explanatory variable that is centered using `scale()` that is used to predict a response variable: ``` d <- data.frame( x=runif(100), y=rnorm(100) ) d <- within(d, s.x <- scale(x)) m1 <- lm(y~s.x, data=d) ``` I'd like to plot the predicted values, but using the original scale of `x` rather than the centered scale. Is there a way to sort of backtransform or reverse scale `s.x`? Thanks!