Create realistic personas by modeling real-world relationships between attributes like age-income correlation, education-salary relationships, and experience-skill dependencies.
Basic Correlations
Define linear relationships between numeric attributes:
basic-correlations.ts
1import { PersonaGroup, NormalDistribution } from '@jamesaphoenix/persona-sdk';2
3const group = new PersonaGroup('Professionals');4
5// Generate personas with age-income correlation6group.generateWithCorrelations(100, {7 attributes: {8 age: new NormalDistribution(35, 8),9 income: new NormalDistribution(75000, 20000),10 yearsExperience: new NormalDistribution(10, 5)11 },12 correlations: [13 // Older people tend to earn more14 { attribute1: 'age', attribute2: 'income', correlation: 0.6 },15 // Age correlates with experience16 { attribute1: 'age', attribute2: 'yearsExperience', correlation: 0.8 },17 // Experience correlates with income18 { attribute1: 'yearsExperience', attribute2: 'income', correlation: 0.7 }19 ]20});21
22// Results in realistic combinations:23// 45-year-old, 18 years exp, $95k income24// 28-year-old, 5 years exp, $65k income
Conditional Dependencies
Add logical constraints and transformations:
conditional-dependencies.ts
1// Add realistic constraints2group.generateWithCorrelations(50, {3 attributes: {4 age: new NormalDistribution(32, 7),5 yearsExperience: new NormalDistribution(8, 4),6 education: new CategoricalDistribution([7 { value: 'High School', probability: 0.2 },8 { value: 'Bachelor', probability: 0.5 },9 { value: 'Master', probability: 0.25 },10 { value: 'PhD', probability: 0.05 }11 ])12 },13 conditionals: [14 {15 // Experience can't exceed working years (age - 18)16 attribute: 'yearsExperience',17 dependsOn: 'age',18 transform: (experience, age) => {19 const maxExperience = Math.max(0, age - 18);20 return Math.min(experience, maxExperience);21 }22 },23 {24 // Adjust income based on education level25 attribute: 'income',26 dependsOn: 'education',27 transform: (baseIncome, education) => {28 const multipliers = {29 'High School': 0.8,30 'Bachelor': 1.0,31 'Master': 1.3,32 'PhD': 1.633 };34 return baseIncome * (multipliers[education] || 1.0);35 }36 }37 ]38});
Common Correlation Patterns
Use built-in correlation patterns for realistic relationships:
correlation-patterns.ts
1import { CommonCorrelations, PersonaCorrelationPresets } from '@jamesaphoenix/persona-sdk';2
3// Use built-in correlation functions4const correlatedIncome = CommonCorrelations.ageIncome(50000, age);5const boundedExperience = CommonCorrelations.ageExperience(experience, age);6const realisticWeight = CommonCorrelations.heightWeight(weight, height);7const educationBonus = CommonCorrelations.educationIncome(income, educationYears);8
9// Use preset correlation configurations10group.generateWithCorrelations(100, {11 ...PersonaCorrelationPresets.REALISTIC_ADULT,12 // Adds common correlations:13 // - Age ↔ Income (0.5)14 // - Age ↔ Experience (0.8)15 // - Height ↔ Weight (0.7)16 // - Education ↔ Income (0.6)17});18
19// Professional preset for workplace personas20group.generateWithCorrelations(50, {21 ...PersonaCorrelationPresets.PROFESSIONAL,22 // Adds workplace-specific correlations:23 // - Experience ↔ Salary (0.8)24 // - Education ↔ Position Level (0.7)25 // - Age ↔ Management Role (0.6)26});
Correlation Types
Linear Correlation
Direct proportional relationship (default):
{ attribute1: 'age', attribute2: 'income', correlation: 0.6, type: 'linear' // As age increases, income increases proportionally}
Exponential Correlation
Accelerating relationship for compound effects:
{ attribute1: 'yearsExperience', attribute2: 'skillLevel', correlation: 0.7, type: 'exponential' // Skill grows faster with more experience}
Logarithmic Correlation
Diminishing returns relationship:
{ attribute1: 'hoursStudied', attribute2: 'testScore', correlation: 0.5, type: 'logarithmic' // Returns diminish with more study time}
💡 Best Practices
- • Keep correlations realistic: Use values between -0.8 and 0.8 for most relationships
- • Add logical constraints: Use conditionals to prevent impossible combinations
- • Layer correlations: Build complex relationships by combining multiple simple ones
- • Test your model: Generate samples and verify the relationships make sense
- • Use presets: Start with built-in patterns and customize as needed