{"id":3931,"date":"2024-03-01T22:59:43","date_gmt":"2024-03-01T21:59:43","guid":{"rendered":"https:\/\/www.psyctc.org\/psyctc\/?post_type=docs&#038;p=3931"},"modified":"2024-06-21T18:12:33","modified_gmt":"2024-06-21T16:12:33","password":"","slug":"transforming-data-variables","status":"publish","type":"docs","link":"https:\/\/www.psyctc.org\/psyctc\/glossary2\/transforming-data-variables\/","title":{"rendered":"Transforming data\/variable(s)"},"content":{"rendered":"\n<p>Technically this could be any transforming of a variable or multiple variables so it could include dichotomising a continuous variable into (say) high\/low or standardising where the aim is to make a lot of different variables all have the same mean and standard deviation.  However, it is generally used for transformations that bring a variable into a distribution shape more like a Gaussian distribution in order to make it fit the assumptions of a parametric test involving the variable.<\/p>\n\n\n\n<p>With the increasing shift away from null hypothesis tests and the increasing use of bootstrapping to avoid assuming that things come from Gaussian distributions, I think transformations are getting pretty rare now in the MH\/therapy research world but here are the gory details just in case you hit a report using them but not really explaining them.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Details<\/h4>\n\n\n\n<p>Here&#8217;s an example.  Imagine you have 710 values from some measure.   Here are the raw data (in a histogram with a smoothed density curve on top).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-1024x1024.png\" alt=\"\" class=\"wp-image-3934\" srcset=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-1024x1024.png 1024w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-300x300.png 300w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-150x150.png 150w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-768x768.png 768w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-1536x1536.png 1536w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none-360x360.png 360w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_none.png 1700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We can see that the distribution is &#8220;right skew&#8221;: it has a &#8220;tail&#8221; off to the right.  The Shapiro-Wilk test (q.v.) is highly statistically significant showing that it&#8217;s vanishingly unlikely that this quite large sample arose from sampling from a population in which the values have a Gaussian distribution.<\/p>\n\n\n\n<p>In this situation, before bootstrapping (q.v.) rendered the preoccupation with Gaussian distributions and parametric <em>versus<\/em> non-parametric tests less important, a researcher might have tried to find a transformation of the data that pulled them closer to a Gaussian distribution.  She might have tried taking the log of the values (as logs shrink large numbers much more than they shrink small numbers so they reduce right skew).  Here&#8217;s that log (to base e) transform of the raw data.  I have added a best fit linear regression line in blue to emphasise that the transformation has reduced the higher values and increased the smaller values relative what a linear transform would have done.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-1024x1024.png\" alt=\"\" class=\"wp-image-3937\" srcset=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-1024x1024.png 1024w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-300x300.png 300w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-150x150.png 150w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-768x768.png 768w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-1536x1536.png 1536w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot-360x360.png 360w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/log_transform_plot.png 1700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>How has that affected the distribution?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-1024x1024.png\" alt=\"\" class=\"wp-image-3933\" srcset=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-1024x1024.png 1024w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-300x300.png 300w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-150x150.png 150w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-768x768.png 768w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-1536x1536.png 1536w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log-360x360.png 360w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_log.png 1700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>That has overdone it and now the distribution is slightly left skew and though the misfit according to the Shapiro-Wilk test has been reduced, this is still not nearly Gaussian.  What about using a square root transformation (square roots, only, for our purposes applicable to positive numbers, also reduce large numbers more than smaller ones).  Here is the transformation mapping this time mapping the square root transform rather than the log transform.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-1024x1024.png\" alt=\"\" class=\"wp-image-3940\" srcset=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-1024x1024.png 1024w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-300x300.png 300w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-150x150.png 150w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-768x768.png 768w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-1536x1536.png 1536w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot-360x360.png 360w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/sqrt_transform_plot.png 1700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can see that that has again, relatively, shrunk the larger values and increased teh smaller values but less so than the log transform did.  So how has that changed the distribution?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-1024x1024.png\" alt=\"\" class=\"wp-image-3932\" srcset=\"https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-1024x1024.png 1024w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-300x300.png 300w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-150x150.png 150w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-768x768.png 768w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-1536x1536.png 1536w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt-360x360.png 360w, https:\/\/www.psyctc.org\/psyctc\/wp-content\/uploads\/2024\/03\/transform_sqrt.png 1700w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Bingo!  The distribution is now, very narrowly, not statistically significantly implausible to have arisen by sampling from a Gaussian population as the Shapiro-Wilk test p value is .0562, above the conventional &#8220;&lt; .05&#8221; criterion.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Try also<\/h4>\n\n\n\n<p><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/bootstrap-methods\/\" title=\"\">Bootstrapping<\/a><br>Dichotomising<br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/distribution-shape\/\" title=\"\">Distribution shape<\/a><br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/gaussian-normal-distribution\/\" title=\"\">Gaussian distribution<\/a><br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/null-hypothesis-significance-testing-nhst-paradigm\/\" title=\"\">Null hypothesis testing (NHST)<\/a><br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/parametric-tests\/\" title=\"\">Parametric tests<\/a><br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/shapiro-wilk-test\/\" title=\"\">Shapiro-Wilk test<\/a><br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/skew-skew-distribution\/\" title=\"\">Skewness<\/a><br><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/standardising-normalising\/\" title=\"\">Standardising\/normalising<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Chapters<\/h4>\n\n\n\n<p>A bit esoteric these days, not covered in the book.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Online resources<\/h4>\n\n\n\n<p>None yet, low on my priorities!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Dates<\/h4>\n\n\n\n<p>First created 1.iii.24, tweaked links 21.vi.24.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Technically this could be any transforming of a variable or multiple variables so it could include dichotomising a continuous variable into (say) high\/low or standardising where the aim is to make a lot of different variables all have the same mean and standard deviation. However, it is generally used for transformations that bring a variable &hellip; <a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/transforming-data-variables\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Transforming data\/variable(s)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[18],"glossaries":[],"doc_tag":[],"knowledge_base":[],"class_list":["post-3931","docs","type-docs","status-publish","hentry","doc_category-om-book"],"year_month":"2026-04","word_count":506,"total_views":"952","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"chris","author_nicename":"chris","author_url":"https:\/\/www.psyctc.org\/psyctc\/author\/chris\/"},"doc_category_info":[{"term_name":"All OM book glossary entries","term_url":"https:\/\/www.psyctc.org\/psyctc\/glossary\/non-knowledgebase\/om-book\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs\/3931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/comments?post=3931"}],"version-history":[{"count":4,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs\/3931\/revisions"}],"predecessor-version":[{"id":4318,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs\/3931\/revisions\/4318"}],"wp:attachment":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/media?parent=3931"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/doc_category?post=3931"},{"taxonomy":"glossaries","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/glossaries?post=3931"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/doc_tag?post=3931"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/knowledge_base?post=3931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}