backtransform `scale()` for plotting

前端 未结 8 2295
别那么骄傲
别那么骄傲 2020-11-28 07:05

I have a explanatory variable that is centered using scale() that is used to predict a response variable:

d <- data.frame(
  x=runif(100),
           


        
8条回答
  •  一个人的身影
    2020-11-28 07:46

    I came across this problem and I think I found a simpler solution using linear algebra.

    # create matrix like object
    a <- rnorm(1000,5,2)
    b <- rnorm(1000,7,5) 
    
    df <- cbind(a,b)
    
    # get center and scaling values 
    mean <- apply(df, 2, mean)
    sd <- apply(df, 2, sd)
    
    # scale data
    s.df <- scale(df, center = mean, scale = sd)
    
    #unscale data with linear algebra 
    us.df <- t((t(s.df) * sd) + mean)
    

提交回复
热议问题