Paired t-test with a custom label


Economist GGPlot Excel Paul Tol Black And White Solarized Stata Tableau Wall Street CanvasXpress
<html>

  <head>
    <!-- Include the CanvasXpress library in your HTML file -->
    <link rel="stylesheet" href="https://www.canvasxpress.org/dist/canvasXpress.css" type="text/css"/>
    <script src="https://www.canvasxpress.org/dist/canvasXpress.min.js"></script>
  </head>

  <body>

    <!-- Create a canvas element for the chart with the desired dimensions -->
    <div>
      <canvas id="canvasId" width="600" height="600"></canvas>
    </div>


    <!-- Create a script to initialize the chart -->
    <script>

      // Use a data frame (2D-array) for the graph
      var data = 

      // Create the configuration for the graph
      var config = {
         "graphType" : "Boxplot",
         "graphOrientation" : "vertical",
         "groupingFactors" : [
            "group"
         ],
         "xAxis" : [
            "extra"
         ],
         "xAxisTitle" : "extra",
         "smpTitle" : "group",
         "smpTitleFontStyle" : "bold",
         "axisTitleFontStyle" : "bold",
         "axisAlgorithm" : "rPretty",
         "smpTextRotate" : 0,
         "showLegend" : false,
         "colorBy" : "group",
         "title" : "Extra sleep by drug (paired t-test)",
         "showStatInference" : true,
         "statInference" : {
            "annotate" : "p",
            "comparisons" : [
               {
                  "groups" : [
                     "1",
                     "2"
                  ],
                  "p" : 0.00283289019738427,
                  "label" : "paired t = -4.06, p = 0.0028"
               }
            ]
         },
         "showBoxplotIfViolin" : true,
         "showViolinBoxplot" : true,
         "colorScheme" : "Dark2"
      }

      // Event used to create graph (optional)
      var events = false

      // Call the CanvasXpress function to create the graph
      var cX = new CanvasXpress("canvasId", data, config, events);

    </script>

  </body>

</html>
<html>

  <head>
    <!-- Include the CanvasXpress library in your HTML file -->
    <link rel="stylesheet" href="https://www.canvasxpress.org/dist/canvasXpress.css" type="text/css"/>
    <script src="https://www.canvasxpress.org/dist/canvasXpress.min.js"></script>
  </head>

  <body>

    <!-- Create a canvas element for the chart with the desired dimensions -->
    <div>
      <canvas id="canvasId" width="600" height="600"></canvas>
    </div>


    <!-- Create a script to initialize the chart -->
    <script>

      // Create the data for the graph
      var data = {
         "y" : {
            "vars" : [
               "extra"
            ],
            "smps" : [
               "Obs1",
               "Obs2",
               "Obs3",
               "Obs4",
               "Obs5",
               "Obs6",
               "Obs7",
               "Obs8",
               "Obs9",
               "Obs10",
               "Obs11",
               "Obs12",
               "Obs13",
               "Obs14",
               "Obs15",
               "Obs16",
               "Obs17",
               "Obs18",
               "Obs19",
               "Obs20"
            ],
            "data" : [
               [
                  0.7,
                  -1.6,
                  -0.2,
                  -1.2,
                  -0.1,
                  3.4,
                  3.7,
                  0.8,
                  0,
                  2,
                  1.9,
                  0.8,
                  1.1,
                  0.1,
                  -0.1,
                  4.4,
                  5.5,
                  1.6,
                  4.6,
                  3.4
               ]
            ]
         },
         "x" : {
            "group" : [
               "1",
               "1",
               "1",
               "1",
               "1",
               "1",
               "1",
               "1",
               "1",
               "1",
               "2",
               "2",
               "2",
               "2",
               "2",
               "2",
               "2",
               "2",
               "2",
               "2"
            ]
         }
      }

      // Create the configuration for the graph
      var config = {
         "graphType" : "Boxplot",
         "graphOrientation" : "vertical",
         "groupingFactors" : [
            "group"
         ],
         "xAxis" : [
            "extra"
         ],
         "xAxisTitle" : "extra",
         "smpTitle" : "group",
         "smpTitleFontStyle" : "bold",
         "axisTitleFontStyle" : "bold",
         "axisAlgorithm" : "rPretty",
         "smpTextRotate" : 0,
         "showLegend" : false,
         "colorBy" : "group",
         "title" : "Extra sleep by drug (paired t-test)",
         "showStatInference" : true,
         "statInference" : {
            "annotate" : "p",
            "comparisons" : [
               {
                  "groups" : [
                     "1",
                     "2"
                  ],
                  "p" : 0.00283289019738427,
                  "label" : "paired t = -4.06, p = 0.0028"
               }
            ]
         },
         "showBoxplotIfViolin" : true,
         "showViolinBoxplot" : true,
         "colorScheme" : "Dark2"
      }

      // Event used to create graph (optional)
      var events = false

            // Call the CanvasXpress function to create the graph
      var cX = new CanvasXpress("canvasId", data, config, events);

    </script>

  </body>

</html>
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/r/cX-statistics6-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
x=read.table("https://www.canvasxpress.org/data/r/cX-statistics6-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
data=y,
smpAnnot=x,
axisAlgorithm="rPretty",
axisTitleFontStyle="bold",
colorBy="group",
colorScheme="Dark2",
graphOrientation="vertical",
graphType="Boxplot",
groupingFactors=list("group"),
showBoxplotIfViolin=TRUE,
showLegend=FALSE,
showStatInference=TRUE,
showViolinBoxplot=TRUE,
smpTextRotate=0,
smpTitle="group",
smpTitleFontStyle="bold",
statInference=list(annotate="p", comparisons=list(list(groups=list(1, 2), label="paired t = -4.06, p = 0.0028", p=0.00283289019738427))),
title="Extra sleep by drug (paired t-test)",
xAxis=list("extra"),
xAxisTitle="extra"
)
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import show_in_browser

if __name__ == "__main__":
  # Define the chart with its data and configuration
  chart: CanvasXpress = CanvasXpress(
    render_to = "statistics6",
    data = {
      "y": {
        "vars": ["extra"],
        "smps": ["Obs1", "Obs2", "Obs3", "Obs4", "Obs5", "Obs6", "Obs7", "Obs8", "Obs9", "Obs10", "Obs11", "Obs12", "Obs13", "Obs14", "Obs15", "Obs16", "Obs17", "Obs18", "Obs19", "Obs20"],
        "data": [
          [0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0, 2, 1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4]
        ]
      },
      "x": {
        "group": ["1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"]
      }
    },
    config = {
      "graphType": "Boxplot",
      "graphOrientation": "vertical",
      "groupingFactors": ["group"],
      "xAxis": ["extra"],
      "xAxisTitle": "extra",
      "smpTitle": "group",
      "smpTitleFontStyle": "bold",
      "axisTitleFontStyle": "bold",
      "axisAlgorithm": "rPretty",
      "smpTextRotate": 0,
      "showLegend": False,
      "colorBy": "group",
      "title": "Extra sleep by drug (paired t-test)",
      "showStatInference": True,
      "statInference": {
        "annotate": "p",
        "comparisons": [
          {
            "groups": ["1", "2"],
            "p": 0.00283289019738427,
            "label": "paired t = -4.06, p = 0.0028"
          }
        ]
      },
      "showBoxplotIfViolin": True,
      "showViolinBoxplot": True,
      "colorScheme": "Dark2"
    },
    width = 600,
    height = 600
  )

  # Display the chart in its own Web page
  show_in_browser(chart)
Run this notebook: Open in Binder
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import graph

graph(
  CanvasXpress(
    render_to = "statistics6",
    data = {
      "y": {
        "vars": ["extra"],
        "smps": ["Obs1", "Obs2", "Obs3", "Obs4", "Obs5", "Obs6", "Obs7", "Obs8", "Obs9", "Obs10", "Obs11", "Obs12", "Obs13", "Obs14", "Obs15", "Obs16", "Obs17", "Obs18", "Obs19", "Obs20"],
        "data": [
          [0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0, 2, 1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4]
        ]
      },
      "x": {
        "group": ["1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"]
      }
    },
    config = {
      "graphType": "Boxplot",
      "graphOrientation": "vertical",
      "groupingFactors": ["group"],
      "xAxis": ["extra"],
      "xAxisTitle": "extra",
      "smpTitle": "group",
      "smpTitleFontStyle": "bold",
      "axisTitleFontStyle": "bold",
      "axisAlgorithm": "rPretty",
      "smpTextRotate": 0,
      "showLegend": False,
      "colorBy": "group",
      "title": "Extra sleep by drug (paired t-test)",
      "showStatInference": True,
      "statInference": {
        "annotate": "p",
        "comparisons": [
          {
            "groups": ["1", "2"],
            "p": 0.00283289019738427,
            "label": "paired t = -4.06, p = 0.0028"
          }
        ]
      },
      "showBoxplotIfViolin": True,
      "showViolinBoxplot": True,
      "colorScheme": "Dark2"
    },
    width = 600,
    height = 600
  )
)
using CanvasXpress

canvasxpress(Dict(
  "y" => Dict(
    "vars" => ["extra"],
    "smps" => ["Obs1", "Obs2", "Obs3", "Obs4", "Obs5", "Obs6", "Obs7", "Obs8", "Obs9", "Obs10", "Obs11", "Obs12", "Obs13", "Obs14", "Obs15", "Obs16", "Obs17", "Obs18", "Obs19", "Obs20"],
    "data" => [
      [0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0, 2, 1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4]
    ]
  ),
  "x" => Dict(
    "group" => ["1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"]
  )
);
  graphType = "Boxplot",
  graphOrientation = "vertical",
  groupingFactors = ["group"],
  xAxis = ["extra"],
  xAxisTitle = "extra",
  smpTitle = "group",
  smpTitleFontStyle = "bold",
  axisTitleFontStyle = "bold",
  axisAlgorithm = "rPretty",
  smpTextRotate = 0,
  showLegend = false,
  colorBy = "group",
  title = "Extra sleep by drug (paired t-test)",
  showStatInference = true,
  statInference = Dict(
    "annotate" => "p",
    "comparisons" => [
      Dict(
        "groups" => ["1", "2"],
        "p" => 0.00283289019738427,
        "label" => "paired t = -4.06, p = 0.0028"
      )
    ]
  ),
  showBoxplotIfViolin = true,
  showViolinBoxplot = true,
  colorScheme = "Dark2"
)
⇧