A woman's expectation of how long she will live appears to affect whether she has sons or daughters.
Male babies may need more nurturing
Dr Sarah Johns, a lecturer in biological anthropology at Kent University, found optimistic women are more likely to have boys.
Dr Johns quizzed 609 women who had recently become mothers.
She found that for every extra year a woman thought she was going to live, the odds of her first-born being a boy increased significantly.
Previous research has found that women in good physical health, and those who have comfortable living conditions have a tendency to give birth to boys.
Conversely, women living in harsh conditions tend to produce more girls.
Among the questions Dr Johns put to the new mothers was how long they expected to live.
Some of the women, who were mostly from lower-middle class and working class backgrounds, believed they would die as young as 40, while others believed they would still be alive at 130.
Girls are the safe bet
Dr Johns believes that an optimistic frame of mind may lead to physical changes in the body that make it more likely that a woman will conceive a male child. For instance, it may alter the level of sex hormones around the time of conception.
She told BBC Radio 4's Today programme it was important that a boy's mother was not only in good physical condition, but that she had a positive outlook and the dynamism required to give him the best possible start in life.
By and large, there was a fair chance that a daughter would go on to have children of her own, she said.
But Dr Johns said that, for a male, the odds were much more variable.
The chances of a son going to reproduce were dependent on whether he actually made it to adulthood at all, and on whether, once adult, he had sufficient qualities to make him an attractive proposition.
She said: "It is much more difficult to raise a son to adulthood. Male foetuses put much more strain on the mother's body, they are more difficult to give birth to, and they are much more likely to take risks.
"If you cannot invest in your son, making sure that he grows up to be successful and attractive to the opposite sex then it is likely he will not reproduce at all."
Dr Peter Bowen-Simpkins, of the Royal College of Obstetricians and Gynaecologists, said it was quite possible that the sex of a baby was decided by factors other than pure chance.
He said: "A lot more boys were born after the huge slaughter of men in the First World War.
"Somehow nature seemed to make up for what was lost."
The research is reported in the journal Biology Letters.