PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

[FIXED] How to create a summary statistics table for transformed variables in r

 October 07, 2022     r, regression, statistics, summary     No comments   

Issue

I want to create a summary statistics table in r for transformed variables. The variables are X, Y and Z. These variables have their original values. A summary statistics table can be created in R like this:

dataSumStatTable <- my.dataframe %>% select(X,Y,Z) 

sum1 <- sumtable(dataSumStatTable, 
         summ=c('min(x)','mean(x)','max(x)','sd(x)','notNA(x)'),
         title="Summary Statistics",
         summ.names=c('Min','Mean','Max','SD','Observations'),
         col.align=c('center','center','center', 'center', 'center'),
         labels=c('X',
                  'Y',
                  'Z',
         group.long = TRUE,
         digits = 2,
         fixed.digits = TRUE,
         align = TRUE,
         out = "viewer")

However, I am using these variables in regression models where all variables are in log. How can I create a summary statistics table for my variables in log?


Solution

You can just call log on the data you want to summarise first.

For example:

Untransformed summary:

> mtcars |> select(hp, drat, wt) |> summary()
       hp             drat             wt       
 Min.   : 52.0   Min.   :2.760   Min.   :1.513  
 1st Qu.: 96.5   1st Qu.:3.080   1st Qu.:2.581  
 Median :123.0   Median :3.695   Median :3.325  
 Mean   :146.7   Mean   :3.597   Mean   :3.217  
 3rd Qu.:180.0   3rd Qu.:3.920   3rd Qu.:3.610  
 Max.   :335.0   Max.   :4.930   Max.   :5.424  

Tranformed:

> mtcars |> select(hp, drat, wt) |> log() |> summary()
       hp             drat             wt        
 Min.   :3.951   Min.   :1.015   Min.   :0.4141  
 1st Qu.:4.570   1st Qu.:1.125   1st Qu.:0.9479  
 Median :4.812   Median :1.307   Median :1.2009  
 Mean   :4.882   Mean   :1.269   Mean   :1.1217  
 3rd Qu.:5.193   3rd Qu.:1.366   3rd Qu.:1.2835  
 Max.   :5.814   Max.   :1.595   Max.   :1.6908  


Answered By - Robert Long
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing