Developer Resources

Complete Documentation & API Reference

Everything you need to integrate X-Weight Pro into your research workflow, from quick start guides to advanced implementation patterns.

Quick Start Guide

Get up and running with X-Weight Pro in under 5 minutes.

1

Get Your API Key

Sign up for a free developer account and obtain your API credentials.

curl -X POST https://api.xweight.pro/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email": "your@email.com", "plan": "developer"}'
2

Install SDK

Choose your preferred programming language and install our SDK.

pip install xweight-pro
# or
conda install -c xweight xweight-pro
3

First Calibration

Run your first sample calibration with just a few lines of code.

from xweight import XWeightClient

client = XWeightClient(api_key="your_api_key")

# Load your data
result = client.calibrate(
    sample_data="sample.csv",
    constraints="constraints.json",
    method="hybrid"
)

print(f"Calibration completed in {result.processing_time}s")
print(f"Sample efficiency: {result.efficiency}%")

Getting Started

Need Help?

Join our developer community for support and best practices.

Get Support

API Reference

Complete reference for all X-Weight Pro API endpoints and methods

Authentication

POST /auth/token

Obtain an access token for API requests.

Request Body

{
  "api_key": "your_api_key",
  "api_secret": "your_api_secret"
}

Response

{
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}

Calibration

POST /calibrate

Submit a calibration job with sample data and constraints.

Parameters

Parameter Type Required Description
sample_data file/array Yes Sample data in CSV or JSON format
constraints object Yes Demographic constraints and targets
method string No Calibration method (default: "hybrid")
bounds object No Weight boundaries {min: 0.1, max: 5.0}

Example Request

curl -X POST https://api.xweight.pro/v1/calibrate \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "sample_data": [...],
    "constraints": {
      "age_18_34": {"target": 0.25, "tolerance": 0.02},
      "age_35_54": {"target": 0.35, "tolerance": 0.02},
      "male": {"target": 0.48, "tolerance": 0.01}
    },
    "method": "hybrid",
    "bounds": {"min": 0.3, "max": 3.0}
  }'

Response

{
  "job_id": "cal_1234567890",
  "status": "completed",
  "results": {
    "weights": [...],
    "efficiency": 94.2,
    "processing_time": 0.42,
    "iterations": 7,
    "convergence": true
  },
  "diagnostics": {
    "weight_distribution": {...},
    "constraint_satisfaction": {...}
  }
}

Job Status

GET /jobs/{job_id}

Check the status of a calibration job.

Response States

  • queued - Job is waiting to be processed
  • running - Job is currently being processed
  • completed - Job completed successfully
  • failed - Job failed with error

Implementation Guide

Best practices and advanced implementation patterns for enterprise integration.

Data Preparation

Proper data formatting is crucial for optimal calibration results.

Sample Data Format

{
  "records": [
    {
      "id": "respondent_001",
      "demographics": {
        "age": 32,
        "gender": "male",
        "region": "northeast",
        "education": "college"
      },
      "initial_weight": 1.0
    }
  ]
}

Constraints Definition

{
  "age_18_34": {
    "target": 0.25,
    "tolerance": 0.02,
    "priority": "high"
  },
  "gender_male": {
    "target": 0.48,
    "tolerance": 0.01,
    "priority": "critical"
  }
}

Error Handling

Implement robust error handling for production systems.

try:
    result = client.calibrate(data, constraints)
    if result.convergence:
        print(f"Success: {result.efficiency}% efficiency")
    else:
        print("Warning: Calibration did not fully converge")
        
except XWeightError as e:
    if e.code == "INSUFFICIENT_DATA":
        # Handle small sample size
        pass
    elif e.code == "CONFLICTING_CONSTRAINTS":
        # Adjust constraints
        pass
    else:
        # Log error and fallback
        logger.error(f"Calibration failed: {e}")

Performance Optimization

Tips for optimizing calibration performance in high-volume environments.

  • Batch Processing: Group multiple small calibrations together
  • Async Operations: Use asynchronous calls for large datasets
  • Caching: Cache demographic profiles for repeated use
  • Streaming: Process large files in chunks

Integration Patterns

Real-time

Immediate calibration for small samples

Batch

Scheduled processing for large datasets

Streaming

Continuous calibration as data arrives

Research Papers & Publications

Academic research and peer-reviewed publications on our methodology

Journal of the American Statistical Association 1992

Calibration estimators in survey sampling.

Deville, J.C., & Särndal, C.E.

The article studies estimating finite-population totals using auxiliary information via weight calibration: starting from design weights 1 / 𝜋 𝑘 1/π k ​ , it seeks new weights that are as close as possible (under a chosen distance measure) to the originals while satisfying calibration equations that force weighted sums of auxiliaries to equal their known population totals. The GREG estimator arises naturally in this framework—efficient and precise...

The Stata Journal 2014

Calibrating survey data using iterative proportional fitting (raking)

Stanislav Kolenikov

In this article implements weight-calibration procedures known as iterative proportional fitting, or raking, of complex survey weights....

Computational Statistics 2023

Entropy Balancing for Causal Effects: A Multivariate Reweighting Method to Produce Balanced Samples in Observational Studies

Jens Hainmueller

This paper proposes entropy balancing, a data preprocessing method to achieve covariate balance in observational studies with binary treatments...

Code Examples

Real-world examples and use cases for common calibration scenarios

Basic Calibration Example

import pandas as pd
from xweight import XWeightClient

# Initialize client
client = XWeightClient(api_key="your_api_key")

# Load sample data
sample_df = pd.read_csv("survey_data.csv")

# Define demographic constraints
constraints = {
    "age_18_34": {"target": 0.25, "tolerance": 0.02},
    "age_35_54": {"target": 0.35, "tolerance": 0.02},
    "age_55_plus": {"target": 0.40, "tolerance": 0.02},
    "gender_male": {"target": 0.48, "tolerance": 0.01},
    "region_urban": {"target": 0.65, "tolerance": 0.03}
}

# Run calibration
result = client.calibrate(
    data=sample_df,
    constraints=constraints,
    method="hybrid",
    bounds={"min": 0.3, "max": 3.0}
)

# Apply weights to data
sample_df['final_weight'] = result.weights
print(f"Calibration efficiency: {result.efficiency}%")

Support & Community

Get help, share knowledge, and connect with other X-Weight Pro users

Documentation

Comprehensive guides and API documentation

Browse Docs

Community Forum

Ask questions and share best practices

Join Forum

Technical Support

Direct support from our engineering team

Submit Ticket

Training

Live workshops and certification programs

View Schedule

Frequently Asked Questions

What data formats are supported?

X-Weight Pro supports CSV, JSON, Excel, SPSS SAV, and Stata DTA formats. We also provide APIs for streaming data directly.

How large datasets can I process?

Our system can handle datasets with millions of records. Processing time scales linearly with sample size, typically 1-2 seconds per 100k records.

Is my data secure?

Yes, all data is encrypted in transit and at rest. We are SOC 2 Type II certified and comply with GDPR and other privacy regulations.

Can I use X-Weight Pro on-premises?

Yes, we offer enterprise on-premises deployments with dedicated support and custom SLA agreements.