Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title>risks</title>
</head>

<body>
  <div id="app">
    <br>
    <div class="columns is-centered">
      <div class="column is-half">
        <h3 class="is-size-5">Sample size:</h3>
        <div class="field has-addons">
          <p class="control"><a class="button" @click="setSampleSize(100)"><span>100</span></a></p>
          <p class="control"><a class="button" @click="setSampleSize(1000)"><span>1,000</span></a></p>
          <p class="control"><a class="button" @click="setSampleSize(10000)"><span>10,000</span></a></p>
        </div>
      </div>
    </div>

    <div class="columns is-centered">

      <div class="column is-half">
        <h3 class="is-size-5">Control</h3>
        <div class="columns is-centered">

          <div class="column is-half">
            <h4><strong>Cancer</strong></h4>
            <p>{{ controlCancer }}</p>
          </div>

          <div class="column is-half">
            <h4><strong>Disease free</strong></h4>
            <p>{{ controlDiseaseFree }}</p>
          </div>

        </div>
      </div>
    </div>

    <div class="columns is-centered">
      <div class="column is-half">
        <input type="range" class="slider" min="10" :max="inputMax" step="10" v-model.number="slider1">
      </div>
    </div>

    <div class="columns is-centered">

      <div class="column is-half">
        <h3 class="is-size-5">Treatment</h3>
        <div class="columns is-centered">

          <div class="column is-half">
            <h4><strong>Cancer</strong></h4>
            <p>{{ treatmentCancer }}</p>
          </div>

          <div class="column is-half">
            <h4><strong>Disease free</strong></h4>
            <p>{{ treatmentDiseaseFree }}</p>
          </div>

        </div>
      </div>
    </div>

    <div class="columns is-centered">
      <div class="column is-half">
        <input type="range" class="slider" min="10" :max="inputMax" step="10" v-model.number="slider2">
      </div>
    </div>

    <div class="columns is-centered">
      <div class="column is-half">
        <hr>
        <div class="content">
          <h3 class="is-size-5">Relative risk</h3>
          <p>Absolute risk for control group (ARC) = Cancer / Sample size = {{ controlCancer }} / {{ sampleSize }} = {{ controlAR }}
          </p>
          <p>Absolute risk for treatment group (ART) = Cancer / Sample size = {{ treatmentCancer }} / {{ sampleSize }} = {{ treatmentAR }}</p>
          <p>Relative risk (RR) = ART / ARC = {{ treatmentAR }} / {{ controlAR }} = <span class="tag is-primary is-medium">{{ relativeRisk
            }}</span></p>
          <br>
          <p>
            From this we can see that absolute risk is a probability, with relative risk being a ratio of those probabilities.</p>
          <hr>
          <h3 class="is-size-5">Odds ratio</h3>
          <p>Odds of cancer in control group (OC) = Cancer / Disease free = {{ controlCancer }} / {{ controlDiseaseFree }} = {{ controlOdds }}</p>
          <p>Odds of cancer in treatment group (OT) = Cancer / Disease free = {{ treatmentCancer }} / {{ treatmentDiseaseFree }} = {{ treatmentOdds }}</p>
          <p>Odds ratio (OR) = OT / OC = {{ treatmentOdds }} / {{ controlOdds }} = <span class="tag is-success is-medium">{{ oddsRatio
            }}</span></p>
          <br>
          <p>
            As you would expect, the odds ratio is the ratio of the odds of the two groups. You might see now why relative risk is considered a more intuitive measure for describing risks.
          </p>
          <hr>
          <p>
            Comparing RR <span class="tag is-primary is-medium">{{ relativeRisk }}</span> to OR <span class="tag is-success is-medium">{{ oddsRatio }}</span> we can see that as a disease becomes more common in a population (represented by its prevalence
            in the control sample), the effect size of our treatment described by the OR is increasingly overstated, compared to the RR. Try changing the sample size to see this for yourself, as the disease prevalence becomes x in 1,000 or x in 10,000.
          </p>
          <br>

        </div>
      </div>
    </div>
  </div>
  <!-- built files will be auto injected -->
</body>

</html>
              
            
!

CSS

              
                input[type=range].slider {
  -webkit-appearance: none;
  width: 100%;
  margin: 6.35px 0;
}
input[type=range].slider:focus {
  outline: none;
}
input[type=range].slider::-webkit-slider-runnable-track {
  width: 100%;
  height: 7.3px;
  cursor: pointer;
  box-shadow: 0px 0px 0px rgba(0, 0, 0, 0), 0px 0px 0px rgba(13, 13, 13, 0);
  background: #645f64;
  border-radius: 0px;
  border: 0px solid #010101;
}
input[type=range].slider::-webkit-slider-thumb {
  box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.35), 0px 0px 2px rgba(13, 13, 13, 0.35);
  border: 0px solid rgba(255, 30, 0, 0);
  height: 20px;
  width: 41px;
  border-radius: 0px;
  background: #25ffa9;
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -6.35px;
}
input[type=range].slider:focus::-webkit-slider-runnable-track {
  background: #645f64;
}
input[type=range].slider::-moz-range-track {
  width: 100%;
  height: 7.3px;
  cursor: pointer;
  box-shadow: 0px 0px 0px rgba(0, 0, 0, 0), 0px 0px 0px rgba(13, 13, 13, 0);
  background: #645f64;
  border-radius: 0px;
  border: 0px solid #010101;
}
input[type=range].slider::-moz-range-thumb {
  box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.35), 0px 0px 2px rgba(13, 13, 13, 0.35);
  border: 0px solid rgba(255, 30, 0, 0);
  height: 20px;
  width: 41px;
  border-radius: 0px;
  background: #25ffa9;
  cursor: pointer;
}
input[type=range].slider::-ms-track {
  width: 100%;
  height: 7.3px;
  cursor: pointer;
  background: transparent;
  border-color: transparent;
  color: transparent;
}
input[type=range].slider::-ms-fill-lower {
  background: #645f64;
  border: 0px solid #010101;
  border-radius: 0px;
  box-shadow: 0px 0px 0px rgba(0, 0, 0, 0), 0px 0px 0px rgba(13, 13, 13, 0);
}
input[type=range].slider::-ms-fill-upper {
  background: #645f64;
  border: 0px solid #010101;
  border-radius: 0px;
  box-shadow: 0px 0px 0px rgba(0, 0, 0, 0), 0px 0px 0px rgba(13, 13, 13, 0);
}
input[type=range].slider::-ms-thumb {
  box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.35), 0px 0px 2px rgba(13, 13, 13, 0.35);
  border: 0px solid rgba(255, 30, 0, 0);
  height: 20px;
  width: 41px;
  border-radius: 0px;
  background: #25ffa9;
  cursor: pointer;
  height: 7.3px;
}
input[type=range].slider:focus::-ms-fill-lower {
  background: #645f64;
}
input[type=range].slider:focus::-ms-fill-upper {
  background: #645f64;
}

              
            
!

JS

              
                new Vue({
  el: "#app",
  data: {
    sampleSize: 100,
    slider1: 40,
    slider2: 20
  },
  computed: {
    inputMax() {
      return this.sampleSize - 10;
    },
    controlCancer() {
      return this.slider1;
    },
    controlDiseaseFree() {
      return this.sampleSize - this.slider1;
    },
    treatmentCancer() {
      return this.slider2;
    },
    treatmentDiseaseFree() {
      return this.sampleSize - this.slider2;
    },
    controlAR() {
      return parseFloat((this.controlCancer / this.sampleSize).toFixed(5)); // can I do this rounding with filter in template to maintain precision?
    },
    treatmentAR() {
      return parseFloat((this.treatmentCancer / this.sampleSize).toFixed(5));
    },
    relativeRisk() {
      return parseFloat((this.treatmentAR / this.controlAR).toFixed(5));
    },
    controlOdds() {
      return parseFloat(
        (this.controlCancer / this.controlDiseaseFree).toFixed(5)
      );
    },
    treatmentOdds() {
      return parseFloat(
        (this.treatmentCancer / this.treatmentDiseaseFree).toFixed(5)
      );
    },
    oddsRatio() {
      return parseFloat((this.treatmentOdds / this.controlOdds).toFixed(5));
    }
  },
  methods: {
    setSampleSize(size) {
      this.sampleSize = size;
    }
  }
});

              
            
!
999px

Console