3
$\begingroup$

Im doing some basic statistics on a dataset of ours. The data is paired samples from patients in a study where we measure the ratio between component A and B in blood (AB-ratio) on people who have been repositioned between the samples or not. We're looking at if there's any difference between the AB-ratio in sample 1 (AB-ratio1) and the AB-ratio in sample 2 (AB-ratio2) in repositioned patients.

I've been using both the raw variables and log-transformed variables.

AB-ratio = A/B. AB-ratio_LOG = log(A)/log(B).

Visually, when plotting the data it appears as if there is a difference between paired samples for repositioned patients, which is also something we see in other analyses. However, wilcoxon signed rank is not significant for the non-logtransformed data.

wilcox.test(AB-ratio1,AB-ratio2,paired=TRUE) #p=0,155
wilcox.test(AB-ratio1_log,AB-ratio2_log,paired=TRUE) #p=0,0053

Is there any reason why it's wrong of me to use the log-transformed variable in this case?

When I use wilcoxon rank sum to compare repositioned patients with non-repositioned patients, we see that the AB-ratio1-AB-ratio2 (AB difference) is greater in the repositioned patients. I can't for the life of me understand how this can be true if the difference between sample 1 and sample 2 is not statistically significant for the repositioned patients to begin with.

Any thoughts?

Below is examples of our data for the AB-ratio and the AB-ratio_log.

AB-ratio1 <- c(3, 3.98907103825137, 0.267379679144385, 7.07070707070707, 2.20224719101124, 
7.33067729083665, 7.15434083601286, 8.22558459422283, 6.31578947368421, 
44, 2.12121212121212, 0.32258064516129, 0.789473684210526, 0.836236933797909, 
1, 1.34328358208955, 3.78504672897196, 0.350877192982456, 0.411522633744856, 
0.9375, 0.651260504201681, 0.888888888888889, 3.98190045248869, 
1.85750636132316, 12.4759615384615, 1.61111111111111, 1.70091324200913, 
7.85930867192238, 1.14647713226205, 1.66666666666667, 0.857142857142857, 
2.16981132075472, 7.13541666666667, 3.00518134715026, 1.31386861313869, 
10.7531380753138, 2.8, 1.49425287356322, 3.93225331369661, 7.48344370860927, 
33.8805970149254, 14, 3.50649350649351, 82.8260869565217, 33.6546184738956, 
6.36655948553055, 0.716049382716049, 0.337078651685393, 1.08225108225108, 
0.436781609195402, 3.19105691056911, 1.55844155844156, 0.413533834586466, 
0.224358974358974, 0.772797527047913, 0.588235294117647, 0.227149810708491, 
0.440087145969499, 0.268041237113402, 13.2407407407407, 14.9002849002849, 
0.798816568047337, 4.85775059824515, 0.549450549450549, 56.4285714285714, 
19.6899224806202, 30.1672240802676, 10.7155025553663, 7.80487804878049, 
0.298507462686567, 4.05405405405405, 0.887096774193548, 1.97916666666667, 
2.39910313901345, 1.47169811320755, 7.94847328244275, 2.31301939058172, 
12.4, 4.8, 0.688259109311741, 0.545454545454546, 0.431034482758621, 
4.42748091603053, 0.536585365853659, 7.22222222222222, 6.39494026704146, 
30.7692307692308, 27.5, 2.16216216216216, 1.66666666666667, 0.365853658536585, 
0.892857142857143, 0.567375886524823, 0.769230769230769, 0.543478260869565, 
1.18852459016393, 1.33333333333333, 3.25301204819277, 3.04498269896194, 
7.59825327510917, 0.808854831843338, 4.21052631578947, 0.669344042838019, 
2.25)

AB-ratio2 <- c(2.63020833333333, 3.28150134048257, 0.224719101123596, 11.8529411764706, 
1.95190947666195, 10.5686032138443, 6.25146886016451, 12.2142857142857, 
5.55555555555556, 37.4193548387097, 1.19047619047619, 0.377358490566038, 
0.573770491803279, 2.24074074074074, 1.15044247787611, 1.53333333333333, 
3.2824427480916, 0.683962264150943, 0.437601296596434, 1.26550868486352, 
0.650925335035099, 0.769230769230769, 4.52914798206278, 2.04778156996587, 
16.0759493670886, 1.25925925925926, 1.07338444687842, 4.97194163860831, 
1.29014697876973, 0.833333333333333, 1.95121951219512, 4.62264150943396, 
4.66321243523316, 4.54761904761905, 1.0546875, 11.1444141689373, 
3.56120826709062, 1.24768946395564, 5.05494505494506, 7.16245487364621, 
49.7560975609756, 10, 3.33333333333333, 74.2696629213483, 30.1492537313433, 
13.1, 0.742268041237113, 0.526315789473684, 1.66666666666667, 
1.0750382848392, 2.44573082489146, 1.55230596175478, 0.586907449209932, 
0.226415094339623, 0.775613886536833, 0.625, 0.252025202520252, 
0.409429280397022, 0.582010582010582, 18, 12.2077922077922, 1.33815551537071, 
3.69109151717847, 0.703218116805721, 90.3703703703704, 20.2097902097902, 
20.2013422818792, 6.44189383070301, 9.44162436548223, 0.27972027972028, 
14.0277777777778, 2.8421052631579, 7.18978102189781, 3.41981132075472, 
1.46341463414634, 9.408, 1.71561051004637, 16.8269230769231, 
3.11111111111111, 0.869565217391304, 0.980392156862745, 1.0752688172043, 
4.60136674259681, 0.621359223300971, 6.21315192743764, 7.50713606089439, 
32.8571428571429, 45.5555555555556, 2.17877094972067, 0.816326530612245, 
0.307692307692308, 0.952380952380952, 0.720720720720721, 0.909090909090909, 
0.495049504950495, 1.08786610878661, 1.42857142857143, 4.35897435897436, 
4.43425076452599, 3.71428571428571, 0.903286829037598, 2.80155642023346, 
0.608695652173913, 1)

AB-ratio1_log <- c(0.403638055400894, 0.437148209069139, 0.16362264070524, 0.519191983969621, 
0.428371742074317, 0.545843340288609, 0.552456365100691, 0.571157365005211, 
0.32914374710378, 0.589053318117168, 0.240186071294515, 0.0793773482041905, 
0.258063512743193, 0.309611441864981, 0.264558297597896, 0.304153290607172, 
0.440716550142183, 0.207228886777308, 0.22801864499786, 0.313098028367874, 
0.38187909611077, 0.164802893085947, 0.447584506566846, 0.405564574574325, 
0.587813920070771, 0.425018874195599, 0.439693366303977, 0.596602138758889, 
0.466310333927957, 0.0977629998397715, 0.134625308755078, 0.338291767532061, 
0.498849007592011, 0.45010764040709, 0.375477492880011, 0.579336444302945, 
0.463651235347023, 0.409445786884048, 0.502188878160711, 0.589513812197819, 
0.615781441473649, 0.517860937476932, 0.36829208285206, 0.738680083783224, 
0.664948012551219, 0.511192449940337, 0.317398214530725, 0.120808847421222, 
0.320363042157243, 0.275683208500602, 0.468012784475757, 0.456500157228622, 
0.235349275003681, 0.188043829453275, 0.425096098928288, 0, 0.308196076349175, 
0.373885958400978, 0.237730420165906, 0.534368855871642, 0.598089770220198, 
0.358677614657448, 0.585033378865562, 0.285244699959532, 0.637817317037343, 
0.613349266852348, 0.660282315924171, 0.649077297858263, 0.484674137670135, 
0.180831000958413, 0.381760866682434, 0.305481270093249, 0.321111628545901, 
0.436489054747789, 0.359705214761306, 0.581759924629659, 0.457486766234792, 
0.523355421290559, 0.434022530330872, 0.280112408042444, 0.192545320636957, 
0.17197127050856, 0.467251518877352, 0.291022237876291, 0.54149541155591, 
0.574213804747546, 0.514479491138187, 0.561154512071733, 0.360924584844037, 
0.233243139591273, 0.121906987075809, 0.278344419458757, 0.270573613599501, 
0.213460268855334, 0.176338904800588, 0.333318454886268, 0.0947800208214054, 
0.410509333808922, 0.435894911897064, 0.513906833723027, 0.424279135076009, 
0.444776718754767, 0.348626766665653, 0.264915773678585)

AB-ratio2_log <- c(0.437211291175664, 0.528727230169076, 0.175793351566841, 0.601413281238528, 
0.441265005933112, 0.597391374790748, 0.578658962222824, 0.611489963475227, 
0.342747472984385, 0.591304531086751, 0.254823861174144, 0.0808291346302037, 
0.206809501618146, 0.440112441191784, 0.274838833701293, 0.326077126084049, 
0.437837604023091, 0.316032499530038, 0.298805543959273, 0.370783294263807, 
0.42023081657227, 0.162018151129826, 0.460943157600411, 0.398075654241726, 
0.621773701685931, 0.43928108473945, 0.45394125115874, 0.534640224356411, 
0.480810680309223, 0, 0.249970666059141, 0.419892583719806, 0.456006621433278, 
0.493383164949647, 0.367868857419249, 0.572160870312266, 0.489772686529065, 
0.455716312690764, 0.532637721215994, 0.582814537575913, 0.639293757673882, 
0.405067840837091, 0.278094243287903, 0.714085328301486, 0.602536931013287, 
0.529317823913941, 0.332135782889205, 0.155137570257304, 0.387266154759708, 
0.461617889023837, 0.460356815922014, 0.432394739228309, 0.346847161598818, 
0.17592312807406, 0.461057717988708, 0, 0.286809362250303, 0.34941739679272, 
0.24351735917341, 0.552988145107735, 0.56151855838931, 0.43028689156432, 
0.559032622689634, 0.359654269587009, 0.695755387777684, 0.634224756358327, 
0.593926639305472, 0.574091267602098, 0.5284738136703, 0.144888400336269, 
0.572492584064002, 0.404882804991899, 0.517033617298075, 0.528438125700113, 
0.364130169439247, 0.602405636729704, 0.425143145542352, 0.558381735780625, 
0.393006808016238, 0.290843635296205, 0.188525090864674, 0.251985459674052, 
0.496579211191557, 0.31944218113231, 0.524875184774422, 0.576922780840938, 
0.478622464627184, 0.622793996733921, 0.374116997562905, 0.163151219683511, 
0.0789501275027734, 0.323868742586923, 0.223242987451848, 0.247439454144716, 
0.174553922897488, 0.323171484177901, 0.0956826906757104, 0.419737503184038, 
0.478756261014483, 0.465209440456144, 0.458932506482668, 0.421170218342954, 
0.344530453619642, 0.188963415090328)
```
$\endgroup$

2 Answers 2

3
$\begingroup$

Inference—either CIs or hypothesis tests—on transformed variables ≠ inference on untransformed variables. Full stop. (A critically important part of this is because $\text{Var}[f(x)]\ne f[\text{Var}(x)]$, unless $f$ is the identity function, and the standard errors which are used to construct both CIs and test statistics depend directly on variance estimates.)

As an example, consider $H_0\text{: }\rho = 0$ (test of Pearson's correlation coefficient equaling 0) for variables $X$ and $Y$. If $Y=X$ $H_0$ should be rejected for any non-tiny sample. However, if $Y=X^2$ (and $X$ is centered on 0), we would never expect to reject $H_0$ regardless of the sample size.

Onto your example with the Wilcoxon sign-rank test: if ABratio1_log is simply the log of ABratio1 (i.e. ABratio1_log <- log(ABratio1)), then you should be getting identical results from the test, since the rank order of data (i.e. what Wilcoxon's sign-rank actually analyzes) is preserved under monotonic transformations (and log is a monotonic transformation, so the Wilcoxon test should give identical results since rank ordering is preserved). However, this is not the case in the data you provided. A comparison in R shows that ABratio1_log does not equal log(ABratio1). Comparing the ranks of ABratio1 with the ranks of ABratio1_log reveals that these ranks are different. ABratio1_log was therefore produced via a non-monotonic transformation, and we are back at the start of my answer: there is no reason to expect inference on transformed data to correspond to inference on untransformed data.

$\endgroup$
2
  • $\begingroup$ Hi, thanks for a great reply! ABratio1_log is not simply log(ABratio1), but ABratio1_log = log(A)/log(B) which yield a different result thus affect rank as well. I'm not sure if I'm just "cheating" a good p-value with the logged variables since the non-transformed ones are not statistically significant. $\endgroup$ Dec 21, 2020 at 12:12
  • 1
    $\begingroup$ @MarcusBådholm You are not "cheating", but you are not performing inference on your untransformed data, either. So if you found a significant difference between ABratio1_log and ABratio2_log that does not mean you found a significant difference between ABratio1 and ABratio2. $\endgroup$
    – Alexis
    Dec 21, 2020 at 17:02
2
$\begingroup$

Comment. Thank you for providing your data. Here are boxplots of differences of pairs for the original data (left) and the logged data:

par(mfrow=c(1,2))
 boxplot(AB.ratio1-AB.ratio2)
  abline(h=0, col="green")
 boxplot(AB.ratio1_log-AB.ratio2_log)
  abline(h=0, col="green")
par(mdeow=c(1,1)

enter image description here

And data summaries:

summary(AB.ratio1-AB.ratio2)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-33.94180  -0.67348  -0.05715  -0.73930   0.35634   9.96588 
length(AB.ratio1-AB.ratio2)
[1] 104
sd(AB.ratio1-AB.ratio2)
[1] 4.724329

Differences are hardly symmetrical and the variability is large compared with the difference of the differences from 0.

summary(AB.ratio1_log-AB.ratio2_log)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-0.19592 -0.04096 -0.01348 -0.01641  0.01325  0.11279 
length(AB.ratio1_log-AB.ratio2_log)
[1] 104
sd(AB.ratio1_log-AB.ratio2_log)
[1] 0.05630934

Differences of logs are roughly symmetrical and relative variability is much smaller.

As you say, the original data show pairs not significantly different from 0, whereas the logged data show significance at the 1% level.

wilcox.test(AB.ratio1,AB.ratio2, pair=T)$p.val
[1] 0.1550347

wilcox.test(AB.ratio1_log,AB.ratio2_log, pair=T)

        Wilcoxon signed rank test with continuity correction

data:  AB.ratio1_log and AB.ratio2_log
V = 1830, p-value = 0.0053
alternative hypothesis: true location shift is not equal to 0

I agree with @Alexis's (+1) explanation for the change in results with logged data. In practice, the meaning of a result based on transformed data is sometimes difficult to visualize or explain, but for this example you have shown that the log scale has a straightforward interpretation.

$\endgroup$
1
  • $\begingroup$ Hi, thanks for the reply! Indeed I understand the why of getting a different result, as log-transformations the way I do it (log(A)/log(B)) changes the ranks and thus affect the signed rank dispite the log transformations being monotonic of themselves. I'm hesitant that I'm finding differences that aren't there. Is using logarithmic transformations this way wrong? A plot(AB.ratio1-AB.ratio2) show that the paired differences are almost never 0, yet the test gives a significance level of 0,15. $\endgroup$ Dec 21, 2020 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.