Does carrying valuable cargo increase odds of being attacked?
Solution 1:
I would have to say yes, solely based on the message that you get right before you are attacked.
"Hostile sub-space scan found valuable cargo."
I haven't tested how often this happens with an empty cargo or anything though, so I can't tell you definitively. It may just be random due to the developers cutting a feature that correlated the likelihood with the value of your cargo, too.
Solution 2:
From my experience, I've found that having more valuables increases both the chance of pirates coming to attack you and the amount of pirates that do. Recently, before I switched to earning a profit from trading, I found a few planets with Gravitino Balls, and, with my combined 30-slot inventory, harvested as many as I could. I found that the second I got out of the atmosphere, I immediately had four pirates chasing me. I was able to get to the space station just above in time, however this was no coincidence.
I proceeded to test my theory by coming up with different amounts of balls, and, although the time it took for them to appear varied slightly, I found that the amount of pirates depended on the value of the goods you're carrying and the (approximate) time depended on the amount of valuable goods you have in storage.
Due to this, I don't recommend harvesting sac venom or any other valuable trading items for money once you have over 500,000. Buy low and sell high, especially with dynamic resonators.