Narrative:

My routing was to the west taking off runway xx. I typically set my heading bug prior to getting a takeoff clearance guessing what I will get given the situation as part of my initial avionics settings. I set it to 340. Upon getting cleared for takeoff I was given a turn to 340 as I expected. Climbing through 1500 on a 340 heading I was asked by tower if I was on a 040 heading. Tower said turn 040 and traffic 12 o'clock; 1600; 1 mile and that he needed an immediate response of in sight. I looked at traffic on my avionics which indicated 100 below; and I then immediately got them visually and gave a quick in sight. I think this stepped on tower calling traffic to aircraft Y. They called in sight and descended and turned left and I kept climbing and turned right. I don't think tower ever heard my in sight call.thinking back; I likely suffered confirmation bias on the initial heading. Having set 340 I heard 340 instead of 040.

Google
 

Original NASA ASRS Text

Title: C441 pilot reported an NMAC during initial climb from APF airport due to communication expectation bias.

Narrative: My routing was to the west taking off Runway XX. I typically set my heading bug prior to getting a takeoff clearance guessing what I will get given the situation as part of my initial avionics settings. I set it to 340. Upon getting cleared for takeoff I was given a turn to 340 as I expected. Climbing through 1500 on a 340 heading I was asked by Tower if I was on a 040 heading. Tower said turn 040 and traffic 12 o'clock; 1600; 1 mile and that he needed an immediate response of in sight. I looked at traffic on my avionics which indicated 100 below; and I then immediately got them visually and gave a quick in sight. I think this stepped on Tower calling traffic to Aircraft Y. They called in sight and descended and turned left and I kept climbing and turned right. I don't think Tower ever heard my in sight call.Thinking back; I likely suffered confirmation bias on the initial heading. Having set 340 I heard 340 instead of 040.

Data retrieved from NASA's ASRS site and automatically converted to unabbreviated mixed upper/lowercase text. This report is for informational purposes with no guarantee of accuracy. See NASA's ASRS site for official report.