Two Way Analysis comparisons

Standard figures from the SimThyr calculation.

Case No. 2 from Kubota et al. showing overt hypothyroidism

Case No. 5 from Kubota et al. showing overt hypothyroidism

Using SimThyr

SimThyr Standard file(s)

This is a .csv file used for many manipulations in R.

The file covers two years but I have used only the last year. Maybe you will be able to understand why later on.

NA_1i_NAt_day.h.m.sdateyearmonthdaytimehourminutesecondTRH_ng.lpTSH_mU.lTSH_mU.lTT4_nmol.lFT4_pmol.lTT3_nmol.lFT3_pmol.lcT3_pmol.lX_NAratioTSH_SumTSH_TSH_SumSPINA_GTSPINA_GDTSHITRH_TSHTT4_FT4TT3_FT3sqrtTSHsqrtTRHsqrtFT4sqrtFT3sqrtTT4
1321900-01-01 00:01:401900-01-011900010100:01:400001403181.757941.8138121.937917.66963.21585.350711693.749NA0.30281953185131513.5234880.1341222027926523.3749600563222428.00014925908312.971985292031331754.194453633266.900999456693980.6010054759190391.3467739231214756.40707313803834.203522332520672.3131580144901511.0425495244531
2431900-01-01 00:03:201900-01-011900010100:03:200003204029.994841.8011121.937917.66963.21585.350711693.749NA0.30281953185131513.5234880.1331830959586763.3892997746855628.00014925908312.964958789360872237.518627505416.900999456693980.6010054759190391.3420506696842763.4822400360924.203522332520672.3131580144901511.0425495244531
3541900-01-01 00:05:001900-01-011900010100:05:000005003443.941541.7948121.937917.66963.21585.350711693.749NA0.30281953185131513.5234880.1327172398126873.3964884817533328.00014925908312.961454795119691918.844160909296.900999456693980.6010054759190391.3397014592811358.68510458370164.203522332520672.3131580144901511.0425495244531
4651900-01-01 00:06:401900-01-011900010100:06:400006401199.191941.7845121.937917.66963.21585.350711693.749NA0.30281953185131513.5234880.1319556019867063.4083507771886828.00014925908312.95569946394808672.0044270103676.900999456693980.6010054759190391.335851788186134.62935026823354.203522332520672.3131580144901511.0425495244531
5761900-01-01 00:08:201900-01-011900010100:08:200008203763.407941.7558121.937917.66963.21585.350711693.749NA0.30281953185131513.5234880.1298333684327593.4421381500355828.00014925908312.939485793509972143.414910582076.900999456693980.6010054759190391.3250660360902861.34662093383794.203522332520672.3131580144901511.0425495244531
6871900-01-01 00:10:001900-01-011900010100:10:000010005208.54841.7487121.937817.66963.21585.350711693.749NA0.30281953185131513.5234880.1293083559507723.4506678178605428.00014925908312.935433854737482978.525761994626.900993797256310.6010054759190391.3223842104320572.17027088767234.203522332520672.3131580144901511.0425449965124
Head() of the Standard file – to get an impression of what to find.

Changes

I stumbled over this image the other day – mixing together two images. Yet recreated in R.

Subtracting from the day before – lag – gives this pattern in TSH and TRH when looked at through Simthyr.

For many of the registrations, you see that there is an opposite movement in TRH and TSH. Though there are registrations where this is not the case. What is the reason? I will, later on, dig into the patterns of the other parameters to look for an explanation.

Looking at TT4 and FT4 gives another picture

Subtracting from the day before – lag – gives this pattern in TT4 and FT4 when looked at through Simthyr.

During this time period, it seems as if both total and free T4 is dropping. I will, later on, insert either TSH or TRH to see if there is a pattern to comment on.

TT3 and FT3 have a pattern totally on their own:

Subtracting from the day before – lag – gives this pattern in TT3 and FT3 when looked at through Simthyr.

Subtle spikes of either FT3 or TT3 during one hour – this is interesting and totally different from the other patterns.

As can be seen – the TRH decrease and in this image, we can see the intervals of FT3 spikes shortens. (Update 23-11-2021) If this pattern also exists in vivo it means that it is difficult to capture the T3 changes as the halflife of T3 is short.

This post will be updated with the same data from a hypothyroid simulation – looking into the changes in the thyroid hormones during hypothyroidism. (19-11-2021)

Standard figures hour split into quartiles

1 q minutes2 q minutes3 q minutes4 q minutes
FT3_pmol.l



Max5.62335.62345.62355.6236
Mean5.6232675.6233445.6234335.623533
Min5.62325.62335.62345.6235
SD5E-055.3e-055E-055E-05
FT4_pmol.l



Max18.607718.610918.613718.6159
Mean18.60625618.60951118.612518.614911
Min18.604918.60818.611318.6139
SD0.000950.0010010.0008220.000672
TRHdiv1000



Max7.7204177.084416.2676836.641718
Mean4.6789923.7287013.7700224.005787
Min1.3528530.4511240.9398592.25577
SD1.842022.1545481.4358541.569699
TSH_mU.l



Max2.73152.68412.57692.4747
Mean2.6673112.6309672.4912.4117
Min2.57192.5572.42532.3814
SD0.0554730.0376120.0538880.030551
TT3_nmol.l



Max3.37963.37973.37973.3798
Mean3.37963.3796113.37973.379733
Min3.37963.37963.37973.3797
SD03.3e-0505E-05
TT4_nmol.l



Max128.4115128.434128.4528128.468
Mean128.401744128.424311128.444867128.461456
Min128.3923128.4142128.4363128.4546
SD0.0065330.0067750.0056930.00463

Update (22-11-2021)

SimThyr – pattern

I have done a little experiment. Subtracted ten and added ten percent to the standard parameters and “surprisingly” it gave the following pattern:

Notice the y axis is logaritmic.

What is obvious from this chart is that there are opposite effects of the parameters on the TSH and the thyroid hormones:

In FT3 there are effects above the ten percent (16% above and 13% below)

TSH variation in 24 hours

TSH variation in 24 hours

Exploring this modelscenario – SimThyr?

Method importing libraries:
library(readr)
library(dplyr)
library(tidyr)
library(tidyverse)
library(WVPlots)
library(ggridges)
library(magrittr)
library(ggplot2)
library(clinfun)
library(e1071) #kurtosis
library(SPINA)
Dataset 1: SimThyr – SimThyr 4.0

The versatile thyroid simulator for education and research. (Ref: SimThyr, RRID:SCR_014351. http://scicrunch.org/browse/resources/SCR_014351. The Digital Object Identifier (DOI) for SimThyr is 10.5281/zenodo.1303822. Project page: https://simthyr.sourceforge.io/index.html)

In this SimThyr simulation 50 days and the standard setting is used. In “preferences” only hours is used. This is due the visualisation model – (WVPlots::ScatterHistN – https://winvector.github.io/WVPlots/articles/WVPlots_examples.html – the action behind is described here: https://github.com/WinVector/WVPlots/blob/main/R/ScatterHistC.R (Note ScatterHistN is at the buttom of the document)) – can’t handle characters (yet?)

Dataset import, tidying and calculations:
CSVdotcsv <- read_csv("http://www.glensbo.dk/Files/Timer50StandardCSV.csv",
                      col_names = TRUE,
                      skip_empty_rows = TRUE,
                      col_types = "-ddddddddd-")%>% slice(-1) 
## Warning: Missing column names filled in: 'X11' [11]
## Warning: 9 parsing failures.
## row  col expected    actual                                                 file
##   1 t    a double day h:m:s 'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'
##   1 TRH  a double ng/l      'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'
##   1 pTSH a double mU/l      'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'
##   1 TSH  a double mU/l      'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'
##   1 TT4  a double nmol/l    'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'
## ... .... ........ ......... ....................................................
## See problems(...) for more details.

Additional calculations and add columns via mutate. The solution for me (as this long string of mutations made problems in the .Rmd file) was to mutate to CSVdotcsv and assign the result to CSVdotcsv. (Tips from Practical Data Science With R, https://livebook.manning.com/book/practical-data-science-with-r-second-edition/chapter-2/v-6/comment-501826)

CSVdotcsv <-               CSVdotcsv %>% 
                        mutate_if(is.character,as.numeric)%>%
                        mutate(ratio = FT3/FT4, 
                           TSH_Sum = (FT4*0.52)+(FT3*0.38)+((FT4+FT3)*0.1),
                           TSH_TSH_Sum = TSH/TSH_Sum,
                           SPINA_GT = SPINA.GT(CSVdotcsv$TSH, CSVdotcsv$FT4),
                           SPINA_GD = SPINA.GD(CSVdotcsv$FT4, CSVdotcsv$FT3),
                           TSHI = estimated.TSHI(CSVdotcsv$TSH, CSVdotcsv$FT4),
                           TRH_TSH = TRH/TSH,
                           TT4_FT4 = TT4/FT4,
                           TT3_FT3 = TT3/FT3)

*
I have used col_types = “cd…..” because this is a uniform dataset I use a lot. It makes it easy to change the format of/ -delete the columns if needed
+
slice(-1) deletes the second row which contains additional headers not necessary for the calculations in these plots. (See warning above)
+
the new columns for calculations (/the slash is not accepted in the header)
+
Below is a str() and summary()

str(CSVdotcsv)
## tibble [43,201 × 18] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ t          : num [1:43201] 0 0 0 0 0 0 0 0 0 0 ...
##  $ TRH        : num [1:43201] 2500 3221 1152 2193 778 ...
##  $ pTSH       : num [1:43201] 4 4 4 4 4 4 4 4 4 4 ...
##  $ TSH        : num [1:43201] 1.81 1.81 1.8 1.77 1.75 ...
##  $ TT4        : num [1:43201] 122 122 122 122 122 ...
##  $ FT4        : num [1:43201] 17.7 17.7 17.7 17.7 17.7 ...
##  $ TT3        : num [1:43201] 3.22 3.22 3.22 3.22 3.22 ...
##  $ FT3        : num [1:43201] 5.35 5.35 5.35 5.35 5.35 ...
##  $ cT3        : num [1:43201] 11694 11694 11694 11694 11694 ...
##  $ ratio      : num [1:43201] 0.303 0.303 0.303 0.303 0.303 ...
##  $ TSH_Sum    : num [1:43201] 13.5 13.5 13.5 13.5 13.5 ...
##  $ TSH_TSH_Sum: num [1:43201] 0.134 0.134 0.133 0.131 0.13 ...
##  $ SPINA_GT   : num [1:43201] 3.37 3.37 3.39 3.42 3.45 ...
##  $ SPINA_GD   : num [1:43201] 28 28 28 28 28 ...
##  $ TSHI       : num [1:43201] 2.97 2.97 2.97 2.95 2.94 ...
##  $ TRH_TSH    : num [1:43201] 1378 1776 639 1237 444 ...
##  $ TT4_FT4    : num [1:43201] 6.9 6.9 6.9 6.9 6.9 ...
##  $ TT3_FT3    : num [1:43201] 0.601 0.601 0.601 0.601 0.601 ...
##  - attr(*, "problems")= tibble [9 × 5] (S3: tbl_df/tbl/data.frame)
##   ..$ row     : int [1:9] 1 1 1 1 1 1 1 1 1
##   ..$ col     : chr [1:9] "t" "TRH" "pTSH" "TSH" ...
##   ..$ expected: chr [1:9] "a double" "a double" "a double" "a double" ...
##   ..$ actual  : chr [1:9] "day h:m:s" "ng/l" "mU/l" "mU/l" ...
##   ..$ file    : chr [1:9] "'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'" "'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'" "'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'" "'http://www.glensbo.dk/Files/Timer50StandardCSV.csv'" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   i = col_skip(),
##   ..   t = col_double(),
##   ..   TRH = col_double(),
##   ..   pTSH = col_double(),
##   ..   TSH = col_double(),
##   ..   TT4 = col_double(),
##   ..   FT4 = col_double(),
##   ..   TT3 = col_double(),
##   ..   FT3 = col_double(),
##   ..   cT3 = col_double(),
##   ..   X11 = col_skip()
##   .. )
summary(CSVdotcsv)
##        t             TRH                pTSH              TSH             TT4       
##  Min.   : 0.0   Min.   :    0.25   Min.   : 0.0002   Min.   :1.081   Min.   :121.9  
##  1st Qu.: 5.0   1st Qu.: 1222.85   1st Qu.: 0.9798   1st Qu.:1.562   1st Qu.:127.0  
##  Median :11.0   Median : 2124.75   Median : 1.6931   Median :2.076   Median :127.8  
##  Mean   :11.5   Mean   : 2519.40   Mean   : 2.1751   Mean   :2.036   Mean   :127.2  
##  3rd Qu.:17.0   3rd Qu.: 3535.33   3rd Qu.: 2.7899   3rd Qu.:2.471   3rd Qu.:128.2  
##  Max.   :23.0   Max.   :11181.38   Max.   :24.7769   Max.   :3.479   Max.   :128.8  
##       FT4             TT3             FT3             cT3            ratio       
##  Min.   :17.66   Min.   :3.216   Min.   :5.351   Min.   :11691   Min.   :0.2998  
##  1st Qu.:18.40   1st Qu.:3.345   1st Qu.:5.565   1st Qu.:12166   1st Qu.:0.3018  
##  Median :18.52   Median :3.374   Median :5.614   Median :12244   Median :0.3024  
##  Mean   :18.44   Mean   :3.351   Mean   :5.575   Mean   :12192   Mean   :0.3024  
##  3rd Qu.:18.57   3rd Qu.:3.378   3rd Qu.:5.621   3rd Qu.:12281   3rd Qu.:0.3031  
##  Max.   :18.66   Max.   :3.385   Max.   :5.632   Max.   :12337   Max.   :0.3041  
##     TSH_Sum       TSH_TSH_Sum         SPINA_GT        SPINA_GD          TSHI      
##  Min.   :13.52   Min.   :0.07605   Min.   :2.422   Min.   :27.72   Min.   :2.527  
##  1st Qu.:14.08   1st Qu.:0.11061   1st Qu.:2.960   1st Qu.:27.91   1st Qu.:2.924  
##  Median :14.18   Median :0.14711   Median :3.255   Median :27.96   Median :3.208  
##  Mean   :14.11   Mean   :0.14432   Mean   :3.424   Mean   :27.96   Mean   :3.158  
##  3rd Qu.:14.21   3rd Qu.:0.17504   3rd Qu.:3.866   3rd Qu.:28.03   3rd Qu.:3.386  
##  Max.   :14.27   Max.   :0.25539   Max.   :4.994   Max.   :28.12   Max.   :3.713  
##     TRH_TSH            TT4_FT4         TT3_FT3     
##  Min.   :   0.125   Min.   :6.901   Min.   :0.601  
##  1st Qu.: 715.948   1st Qu.:6.901   1st Qu.:0.601  
##  Median :1117.158   Median :6.901   Median :0.601  
##  Mean   :1186.705   Mean   :6.901   Mean   :0.601  
##  3rd Qu.:1583.254   3rd Qu.:6.901   3rd Qu.:0.601  
##  Max.   :4519.021   Max.   :6.901   Max.   :0.601
Result:

From this scatterplot you can see TSH varies a lot during 24 hours (reflecting the diurnal nature of TSH). For each hour the number of readings reflects pooled data from 50 days.Likevise the data show higher TSH in the late night and early morning and opposite trend afternoon and evening.Consequences for blood sampling? Another observation is these two TSH values are skeewed – either left or right.

*
50 days 24h
kurtosis(CSVdotcsv$TSH) # -1.209175
+
50 days from 00:00 to 07:00
kurtosis(CSV_subset_0_7$TSH) #0.1163531
+
50 days from 08:00 to 15:00
kurtosis(CSV_subset_8_15$TSH) #-1.056109
+
50 days from 16:00 to 24.00
kurtosis(CSV_subset_16_24$TSH) #-0.4848253
+
50 days only 08:00
kurtosis(CSV_subset$TSH) #-0.2717369 only numbers from 8.00?????

FIG. 1

plot of chunk unnamed-chunk-1

For TSH you see an interesing pattern with a clear shift during the day.

summary(CSVdotcsv)
##        t             TRH                pTSH              TSH             TT4       
##  Min.   : 0.0   Min.   :    0.25   Min.   : 0.0002   Min.   :1.081   Min.   :121.9  
##  1st Qu.: 5.0   1st Qu.: 1222.85   1st Qu.: 0.9798   1st Qu.:1.562   1st Qu.:127.0  
##  Median :11.0   Median : 2124.75   Median : 1.6931   Median :2.076   Median :127.8  
##  Mean   :11.5   Mean   : 2519.40   Mean   : 2.1751   Mean   :2.036   Mean   :127.2  
##  3rd Qu.:17.0   3rd Qu.: 3535.33   3rd Qu.: 2.7899   3rd Qu.:2.471   3rd Qu.:128.2  
##  Max.   :23.0   Max.   :11181.38   Max.   :24.7769   Max.   :3.479   Max.   :128.8  
##       FT4             TT3             FT3             cT3            ratio       
##  Min.   :17.66   Min.   :3.216   Min.   :5.351   Min.   :11691   Min.   :0.2998  
##  1st Qu.:18.40   1st Qu.:3.345   1st Qu.:5.565   1st Qu.:12166   1st Qu.:0.3018  
##  Median :18.52   Median :3.374   Median :5.614   Median :12244   Median :0.3024  
##  Mean   :18.44   Mean   :3.351   Mean   :5.575   Mean   :12192   Mean   :0.3024  
##  3rd Qu.:18.57   3rd Qu.:3.378   3rd Qu.:5.621   3rd Qu.:12281   3rd Qu.:0.3031  
##  Max.   :18.66   Max.   :3.385   Max.   :5.632   Max.   :12337   Max.   :0.3041  
##     TSH_Sum       TSH_TSH_Sum         SPINA_GT        SPINA_GD          TSHI      
##  Min.   :13.52   Min.   :0.07605   Min.   :2.422   Min.   :27.72   Min.   :2.527  
##  1st Qu.:14.08   1st Qu.:0.11061   1st Qu.:2.960   1st Qu.:27.91   1st Qu.:2.924  
##  Median :14.18   Median :0.14711   Median :3.255   Median :27.96   Median :3.208  
##  Mean   :14.11   Mean   :0.14432   Mean   :3.424   Mean   :27.96   Mean   :3.158  
##  3rd Qu.:14.21   3rd Qu.:0.17504   3rd Qu.:3.866   3rd Qu.:28.03   3rd Qu.:3.386  
##  Max.   :14.27   Max.   :0.25539   Max.   :4.994   Max.   :28.12   Max.   :3.713  
##     TRH_TSH            TT4_FT4         TT3_FT3     
##  Min.   :   0.125   Min.   :6.901   Min.   :0.601  
##  1st Qu.: 715.948   1st Qu.:6.901   1st Qu.:0.601  
##  Median :1117.158   Median :6.901   Median :0.601  
##  Mean   :1186.705   Mean   :6.901   Mean   :0.601  
##  3rd Qu.:1583.254   3rd Qu.:6.901   3rd Qu.:0.601  
##  Max.   :4519.021   Max.   :6.901   Max.   :0.601
24 hour

In this TSH example you may see another trend in the development during the day – the height of the ridges changes as does the width

## Picking joint bandwidth of 0.0266
## Picking joint bandwidth of 0.0266

plot of chunk ggplot1

# Example of the code behind the the TRH plot
ggplot(CSVdotcsv, aes(x = TRH , y = as.factor(t), fill = as.factor(t))) + #as factor provides the legend for hour
  #ggplot(CSVdotcsv, aes(x = TSH, y = t, group = t)) + # important to add group =
  geom_density_ridges2(scale = 0.9) + #ridges 2 clearer to view
  scale_y_discrete(expand = c(0, 0)) +     # will generally have to set the `expand` option
  scale_x_continuous(expand = c(0, 0)) +   # for both axes to remove unneeded padding
  coord_cartesian(clip = "off") + # to avoid clipping of the very top of the top ridgeline
  theme_ridges() +
  stat_density_ridges(quantile_lines = TRUE) +
  labs( title = "TRH - 24 hours",caption = "J.W.Dietrich - SPINA package" ) + 
  scale_fill_cyclical(values = c("#4040B0", "#9090F0"))
## Picking joint bandwidth of 243
## Picking joint bandwidth of 243

plot of chunk ggplot2

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.