AveragePointsExpected = function(ThreesMade,ThreesAttempted,FoulsOnThreesNotAndOnes,AndOnesOnThrees, ReboundRateOnThrees,TwosMade,TwosAttempted,FoulsOnTwosNotAndOnes, AndOnesOnTwos,ReboundRateOnTwos,FreeThrowPercentage, ReboundRateOnFreeThrows,ReboundPoints,OnReboundMissAndRebound, ReboundTORate,FirstTORate) { NoReboundOnThreesTotal = (ThreesMade * 3) + ((3 * FoulsOnThreesNotAndOnes + AndOnesOnThrees) * FreeThrowPercentage) NoReboundOnTwosTotal = (TwosMade * 2) + ((2 * FoulsOnTwosNotAndOnes + AndOnesOnTwos) * FreeThrowPercentage) ReboundsThrees = (ThreesAttempted - ThreesMade) * ReboundRateOnThrees ReboundsTwos = (TwosAttempted - TwosMade) * ReboundRateOnTwos ReboundsFreeThrows = (1-FreeThrowPercentage) * (FoulsOnThreesNotAndOnes + FoulsOnTwosNotAndOnes + AndOnesOnThrees + AndOnesOnTwos) * ReboundRateOnFreeThrows MissAndRebound = (ReboundsThrees + ReboundsTwos + ReboundsFreeThrows) / (ThreesAttempted + FoulsOnThreesNotAndOnes + TwosAttempted + FoulsOnTwosNotAndOnes) FirstPoints = (NoReboundOnThreesTotal + NoReboundOnTwosTotal) / (ThreesAttempted + FoulsOnThreesNotAndOnes + TwosAttempted + FoulsOnTwosNotAndOnes) SecondChancePoints = (MissAndRebound * (1-ReboundTORate) * ReboundPoints) / (1-(OnReboundMissAndRebound * (1-ReboundTORate))) AveragePointsTeam = ((1-FirstTORate) * FirstPoints) + ((1-FirstTORate) * SecondChancePoints) AveragePointsPlayer = FirstPoints + SecondChancePoints Points = c(FirstPoints,FirstPoints * (1 -FirstTORate),AveragePointsTeam,AveragePointsPlayer) Points }