FreeExam

Experiment Summary Code

Original Python data analyst interviews on experiment evidence, analysis-unit support, uncertainty kernels, finite assignment tails, multiplicity, and decision sensitivity.

These problems are original practice. They are not questions from a named employer or a live hiring loop.

  1. 1.Reconcile frozen assignments with observed exposure evidence

    Write exposure_audit(assignments, exposures). assignments maps users to string arms; exposures lists [user,arm]. Return dict matched/wrong_arm/unassigned row-index lists in input order; unassigned iff user absent. Also unseen=sorted assigned users with no exposure in ANY arm, mixed=sorted assigned users exposed to >1 distinct arm. Repeated rows add evidence, not new arms. No mutation.

  2. 2.Aggregate to assigned units before taking arm means

    Write assigned_event_means(assignments, events). assignments maps users to c/t; additive events [user,value], finite exact decimals. Assume complete capture: assigned users without events have total 0. Return {"arms":[arm,assigned_count,total,mean_or_None] in c/t order,"unassigned":unknown-user event indices}. Exclude those events. Arm means divide by assigned users, not event rows. No mutation.

  3. 3.Audit treatment consistency at the declared cluster grain

    Write cluster_assignments(rows). String rows [cluster,user,arm] may repeat. Return [cluster,sorted_distinct_arms,distinct_user_count,mixed_bool] sorted by cluster; mixed iff >1 observed arm. Identical repeats add no users/arms. The same user can occur in multiple clusters; report each independently. Conflicting arm evidence for one user still makes its cluster mixed. No mutation.

  4. 4.Keep assigned and observed outcome support separate

    Write outcome_support(assignments, outcomes). assignments maps users to c/t; outcomes maps ids to finite values or None. Assigned absent/None outcomes are missing; 0 observed. Return {"arms":[arm,assigned_count,observed_count,missing_count,observation_rate_or_None] in c/t order,"extra":sorted outcome ids outside assignments}. Rate uses assigned count; extras supply no arm support. No mutation.

  5. 5.Separate absolute changes from relative baseline support

    Write mean_lift(control, treatment). Each is a nonnegative finite exact decimal mean or None. Return {"absolute":treatment-control,"relative_percent":100*(treatment-control)/control}. If either mean is None both outputs are None. If control=0 absolute change is defined but relative_percent is None, including 0->0. Do not replace unsupported relative lift by zero or mutate.

  6. 6.Retain sample-variance support in a difference of means

    Write mean_difference(control, treatment). Finite exact decimal lists. Return {"difference":mean_t-mean_c,"variance":sc**2/nc+st**2/nt,"se":sqrt(variance)}; s**2 is SAMPLE variance, denominator n-1. Either arm empty: all None. Either n<2: only variance/se None. Constant supported samples can give variance 0. Supplied independent-unit kernel; no test or interval. No mutation.

  7. 7.Compute variance-weighted Welch degrees of freedom

    Write welch_df(nc, vc, nt, vt). Counts integers>=0; sample variances finite exact decimals>=0 or None. If count<2 or either variance None, return None. Otherwise a=vc/nc,b=vt/nt; return (a+b)**2/(a*a/(nc-1)+b*b/(nt-1)), or None if denominator=0. Inputs are variances, not standard deviations. Compute no t statistic, p-value or assumption validation. No mutation.

  8. 8.Scale a mean contrast by pooled sample spread

    Write pooled_difference(control, treatment). Each summary [n,mean,sample_variance] has integer n>=0, finite exact values or None. Return (mean_t-mean_c)/sqrt(((nc-1)*vc+(nt-1)*vt)/(nc+nt-2)). If either n<2, any mean/variance None, or pooled variance=0 return None. Variances are nonnegative. Use degrees-of-freedom weights, not an unweighted variance mean. No mutation.

  9. 9.Use common paired support for mean-change uncertainty

    Write paired_summary(rows). Rows [control_or_None,treatment_or_None], finite exact decimals. Keep complete pairs; d=t-c. Return dict n,excluded,mean,variance,se: mean=mean(d); variance=sum((d-mean)**2)/(n*(n-1)), se=sqrt(variance). For n=0 mean is None; n<2 variance/se None. Missing either endpoint excludes the pair, while zero endpoints are observed. No mutation.

  10. 10.Use cluster counts in an equal-cluster mean contrast

    Write cluster_effect(rows). Rows [cluster,arm,value], arm c/t, finite exact values; cluster belongs to one arm. Average rows within cluster, then cluster means equally per arm. Return {"clusters":[nc,nt],"difference":mean_t-mean_c,"se":sqrt(sc**2/nc+st**2/nt)} using SAMPLE variance of cluster means. Empty arm gives difference None; either arm <2 clusters gives se None. No mutation.

  11. 11.Apply one declared stratum mixture to arm contrasts

    Write stratum_effect(weights, summaries). Exact nonnegative weights sum>0; summaries maps stratum to [sum_c,nc,sum_t,nt], exact sums, integer counts>=0. Normalize weights. A positive-weight stratum absent or either count 0 is unsupported. Return {"effect":weighted mean of mean_t-mean_c or None if unsupported,"unsupported":sorted strata}. Ignore zero-weight/extra strata. No mutation.

  12. 12.Retain numerator-denominator covariance in ratio uncertainty

    Write ratio_summary(rows). Unit rows [numerator,denominator>=0], finite exact decimals. Let n=len(rows), R=sum(x)/sum(y), e_i=x_i-R*y_i. Return {"ratio":R,"variance":sample_variance(e)/(n*mean(y)**2),"se":sqrt(variance)}. Zero denominator total gives all None; n<2 gives variance/se None. This is a supplied delta-method variance kernel, not exact interval coverage. No mutation.

  13. 13.Fit a pooled adjustment on common covariate-outcome support

    Write adjusted_means(rows). Rows [arm,pre_or_None,outcome_or_None], arm c/t, exact values. On complete rows compute pooled xbar,ybar; theta=sum((x-xbar)*(y-ybar))/sum((x-xbar)**2). Adjust y-theta*(x-xbar). Return dict theta,center=xbar,arms=[arm,complete_count,adjusted_mean] in c/t order,excluded count. No complete rows: center None; zero x spread: theta/adjusted means None. No mutation.

  14. 14.Summarize supplied deletion estimates without resampling

    Write jackknife_summary(full, leave_one). Finite exact decimal estimates; n=len(leave_one). For n>=2 let m=mean(leave_one), bias=(n-1)*(m-full), corrected=full-bias, se=sqrt((n-1)/n*sum((estimate-m)**2)). Return {"bias":bias,"corrected":corrected,"se":se}; n<2 gives None. The leave-one-out estimates are supplied, not validated or regenerated. No mutation.

  15. 15.Interpolate endpoints from supplied replicate estimates

    Write replicate_interval(replicates, alpha). Finite exact decimal estimates; 0<=alpha<=1. Sort n estimates. Quantile q uses h=(n-1)*q and linear interpolation between floor(h)/ceil(h) positions. Return [quantile(alpha/2),quantile(1-alpha/2)], or None if empty. Repeated estimates retain multiplicity. Do not resample, use nearest ranks, or claim coverage from these numbers alone. No mutation.

  16. 16.Enumerate indexed fixed-size treatment assignments

    Write assignment_tail(values, treated). N=2..10 finite exact values; treated has unique indices, 1<=k<N. D=treated mean minus other mean. Enumerate ALL k-index subsets equally. Return {"observed":D,"p":fraction with abs(D_subset)>=abs(D_observed),"assignments":subset count}. Retain equal-valued indexed assignments; no +1 correction. Use this inclusive absolute-tail convention. No mutation.

  17. 17.Keep every indexed sign assignment in a paired null kernel

    Write signflip_tail(differences). <=12 finite exact paired differences. Under the supplied null, every indexed +/- sign vector is equally likely. Return fraction with abs(mean(signed_differences))>=abs(mean(original)), including equality; empty input gives None. Enumerate all 2**n assignments, retaining duplicate sums and zero-difference sign choices. No +1 correction, resampling or mutation.

  18. 18.Check expected allocation support before Pearson scoring

    Write allocation_score(weights, counts). Nonnegative exact arm weights sum>0; counts are nonnegative integers. Expected E_arm=N*weight/sum(weights), N=sum(counts), over UNION keys; absent weight/count=0. Return {"statistic":sum((O-E)**2/E),"unsupported":sorted arms with E=0,O>0}. Such arms or N=0 make statistic None; E=O=0 adds no term. No p-value, smoothing or mutation.

  19. 19.Preserve prefix maxima in Holm adjusted p-values

    Write holm_adjust(pvalues). Id->finite exact p in [0,1]. Sort by (p,id), m tests. At 1-based rank i compute a_i=min(1,max over j<=i of (m-j+1)*p_j). Return [id,adjusted_p] sorted by id, retaining every supplied test. Empty map gives []. Apply exact decimal ordering/ties. This numeric kernel does not validate p-values or inferential assumptions. No mutation.

  20. 20.Use suffix minima for Benjamini-Hochberg adjustments

    Write bh_adjust(pvalues). Id->finite exact p in [0,1]. Sort by (p,id), m tests. At 1-based rank i, q_i=min(1,min over j>=i of m*p_j/j). Return [id,adjusted_p] sorted by id; retain every supplied test and exact decimal ties. Empty map gives []. Compute the numeric procedure only; validity of p-values and dependence conditions is not checked. No mutation.

  21. 21.Combine interval guardrails with unknown support

    Write guardrail_summary(floors, intervals). Exact floors: metric->minimum; intervals maps metric to [low,high], low<=high, or None. Missing/None is uncertain. Upper<floor fails; lower>=floor passes; otherwise uncertain. Return {"decision":"fail" if any fail, else "unknown" if any uncertain, else "pass","failed":sorted names,"uncertain":sorted names}. Ignore extras; empty floors pass. No mutation.

  22. 22.Retain planned multiplicity when test results are missing

    Write planned_rejections(planned, pvalues, alpha). planned lists unique ids; pvalues maps ids to exact p in [0,1] or None; alpha in [0,1]. With m=len(planned), reject observed planned tests iff p<=alpha/m. Return {"rejected":sorted ids,"missing":sorted absent/None ids,"unexpected":sorted pvalue keys outside planned}. Empty plan rejects none. Do not shrink m to observed-test count. No mutation.

  23. 23.Combine supplied effects by declared inverse variance

    Write replication_summary(rows). Rows [effect,variance>0], finite exact decimals. w=1/variance, W=sum(w), mu=sum(w*effect)/W. Return {"effect":mu,"se":sqrt(1/W),"q":sum(w*(effect-mu)**2)}, or None if no rows. Use inverse VARIANCE, not inverse standard deviation. This supplied fixed-effect/heterogeneity kernel does not check study independence or compute significance. No mutation.

  24. 24.Find a minimal count from a supplied variance inequality

    Write target_count(variance, z, delta). Finite exact decimals: variance>=0,z>=0,delta>0. Return the smallest INTEGER n>=2 satisfying n*delta**2>=2*z**2*variance. Compute the boundary exactly, without floating-ceil overshoot. This is the supplied equal-arm variance target only, not a complete power calculation or a guarantee about an actual experiment. No mutation.

  25. 25.Optimize an integer variance split with fixed support minima

    Write arm_allocation(total, vc, vt). total integer 4..500; finite exact variance inputs vc,vt>=0. Choose nc+nt=total, both>=2, minimizing vc/nc+vt/nt. Return {"control":nc,"treatment":nt,"variance":minimum}, ties by smaller nc. Evaluate INTEGER allocations; do not round a continuous optimum without checking. This supplied objective assumes independent arm means. No mutation.

  26. 26.Keep all four cells in an unscaled interaction contrast

    Write interaction_summary(means). Map cell names "00","01","10","11" to finite exact means or None; extras ignored. Return {"contrast":mean11-mean10-mean01+mean00,"missing":sorted absent/None required cells}. If any required cell missing, contrast is None. Zero means are observed. This is the unscaled four-cell contrast, not an independence check or a causal identification claim. No mutation.

  27. 27.Orient complete adjacent switchback pairs consistently

    Write switchback_summary(blocks). Ordered [arm,value_or_None] rows, arm c/t, exact values. Pair positions (0,1),(2,3),...; dangling last row is excluded. Other exclusions: missing value, then same arm. Return {"pairs":[pair_index,t-c],"excluded":[pair_index,"dangling"/"missing"/"same_arm"],"mean":mean complete pair differences or None}, in pair order. No re-pairing across exclusions or mutation.

  28. 28.Trim arm tails by count using retained support

    Write trimmed_contrast(control, treatment, fraction). Finite exact value lists; 0<=fraction<.5. In each sorted arm of n rows, remove k=floor(fraction*n) from EACH tail. Return {"arms":[arm,k,retained_count,retained_mean_or_None] in c/t order,"difference":mean_t-mean_c or None if either empty}. Use exact decimal floor and retained denominator; fraction=0 retains all. Do not winsorize or mutate.

  29. 29.Bound a contrast using declared missing-outcome support

    Write attrition_bounds(control, treatment). Each [N,observed_sum,n_observed], integer 0<=n_observed<=N and exact 0<=sum<=n_observed; outcomes lie in [0,1]. Arm mean bounds: sum/N to (sum+N-n_observed)/N. Return {"lower":t_low-c_high,"upper":t_high-c_low}; either N=0 gives both None. Missing outcomes stay in assigned denominators. Logical bounds, no missingness model. No mutation.

  30. 30.Audit unit deletion against a frozen practical-effect rule

    Write deletion_sensitivity(rows, threshold). Rows [unique_id,arm,value], arm c/t, exact values; both arms nonempty. Baseline D=mean_t-mean_c; decision D>=threshold. Delete each row; an emptied arm is unsupported, otherwise recompute D and flag decision flips. Return {"baseline":D,"flips":[id,new_D],"stable":ids,"unsupported":ids}, input-order lists. Sensitivity only, not significance. No mutation.