Convert an Odds Ratio to Cohen's d

Quick Overview

Write a SQL query that converts each study's odds ratio to Cohen's d with the log-odds scaling constant 0.5513, rounded to four decimals and sorted by study. It tests use of the natural logarithm, numeric rounding in PostgreSQL, and how effect sizes move between the odds ratio and standardized mean difference scales.

Convert an Odds Ratio to Cohen's d

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

The `study_estimates` table has one row per study with `study_id` and `odds_ratio`. Convert each odds ratio to Cohen's d using $d = \ln(\text{odds ratio}) \times 0.5513$. Return one row per study with `study_id`, `odds_ratio` and `cohens_d` rounded to 4 decimals. ```hint Which logarithm Check which base each PostgreSQL log function uses before you pick one. ``` ### Input Table(s) Table `study_estimates` (primary key `study_id`): | Column | Type | Meaning | |---|---|---| | `study_id` | INT | Study identifier | | `odds_ratio` | NUMERIC(8,2) | Odds ratio reported by the study | ### Output Contract One row per study with these columns, in this order: | Column | Definition | Rounding | |---|---|---| | `study_id` | From the input | none | | `odds_ratio` | From the input, unchanged | none | | `cohens_d` | `ln(odds_ratio) * 0.5513` | 4 decimals | Sort the rows by `study_id` ascending. ### Example Input `study_estimates`: | study_id | odds_ratio | |---|---| | 894 | 2.95 | | 826 | 0.92 | | 577 | 5.83 | | 535 | 1.10 | Expected output: | study_id | odds_ratio | cohens_d | |---|---|---| | 535 | 1.10 | 0.0525 | | 577 | 5.83 | 0.9720 | | 826 | 0.92 | -0.0460 | | 894 | 2.95 | 0.5964 | For study 894, ln(2.95) ≈ 1.0818 and 1.0818 × 0.5513 ≈ 0.5964. Study 826 has an odds ratio below 1, so its log and its d are negative: ln(0.92) ≈ -0.0834, which gives -0.0460. ### Constraints and Clarifications - `study_id` is unique. - `odds_ratio` is positive and never NULL. - Use the constant 0.5513 as given. It is $\sqrt{3}/\pi$ rounded to four decimals. - An odds ratio of exactly 1 maps to a d of 0.

Overview: Write a SQL query that converts each study's odds ratio to Cohen's d with the log-odds scaling constant 0.5513, rounded to four decimals and sorted by study. It tests use of the natural logarithm, numeric rounding in PostgreSQL, and how effect sizes move between the odds ratio and standardized mean difference scales.

General logo
General
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

The study_estimates table has one row per study with study_id and odds_ratio. Convert each odds ratio to Cohen's d using d=ln⁡(odds ratio)×0.5513d = \ln(\text{odds ratio}) \times 0.5513. Return one row per study with study_id, odds_ratio and cohens_d rounded to 4 decimals.

Input Table(s)

Table study_estimates (primary key study_id):

ColumnTypeMeaning
study_idINTStudy identifier
odds_ratioNUMERIC(8,2)Odds ratio reported by the study

Output Contract

One row per study with these columns, in this order:

ColumnDefinitionRounding
study_idFrom the inputnone
odds_ratioFrom the input, unchangednone
cohens_dln(odds_ratio) * 0.55134 decimals

Sort the rows by study_id ascending.

Example

Input study_estimates:

study_idodds_ratio
8942.95
8260.92
5775.83
5351.10

Expected output:

study_idodds_ratiocohens_d
5351.100.0525
5775.830.9720
8260.92-0.0460
8942.950.5964

For study 894, ln(2.95) ≈ 1.0818 and 1.0818 × 0.5513 ≈ 0.5964. Study 826 has an odds ratio below 1, so its log and its d are negative: ln(0.92) ≈ -0.0834, which gives -0.0460.

Constraints and Clarifications

  • study_id is unique.
  • odds_ratio is positive and never NULL.
  • Use the constant 0.5513 as given. It is 3/π\sqrt{3}/\pi rounded to four decimals.
  • An odds ratio of exactly 1 maps to a d of 0.