2011-01-10 133 views
0

我已經修改了給我這裏VBA陣列功能:Excel Generate Normalized DataVBA:生成數據,模仿的具體參數(平均,StdDev..etc)

這個問題會解釋我是什麼了。


下載Excel我使用完全理解:

http://www.mediafire.com/?smq5tl9poitdacc


我現在用的是如下數據(左邊是我輸入的數據進行基於價值,右側是生成的數據結果):

alt text

正如您所看到的,%差異對於平均點擊非常有用,但當存在較高的Day StdDev(Day +/-)時,Click/Time會關閉。當有低日STDDEV的差接近0

我想這是因爲由於NoClickDays_Total(這是間接地用來確定運行AVG)被「猜中」了var NoClickDaysPerClick_Running_Avg變得不準確因爲高StdDev增加了隨機性,原始的「猜測」變得越來越不準確。

我不知道這是否是問題,或者如果它是我能怎麼連解決這個問題。

我只是尋找最好的方式來做我想要的東西的建議。我不知道stdDev爲什麼離得太遠,但那不是什麼大不了的事。我寧願有一個比任何其他更準確的點擊/時間 - 無論什麼日子StdDev是什麼。


這裏是我的VBA函數:

Function ClickSpacer(Total_Days As Long, ClicksPerDay_Desired_Avg As Double, Clicks_Desired_Deviation As Double, Clicks_Min As Integer, Clicks_Max As Integer, TotalClicksOverTotalDays_Desired_Avg As Double, NoClickDays_Desired_Deviation As Double, NoClickDays_Min As Integer, NoClickDays_Max As Integer) 


    Dim Day_Array() As Integer 
    ReDim Day_Array(1 To Total_Days, 1 To 1) 

    Dim NumDaysToGetClicks As Double 
    Dim ClickOffset As Long 

    Dim Clicks_Total As Long 
    Dim Clicks_SoFar As Long 
    Dim Clicks_Remaining As Long 


    Dim NoClickDaysPerClick_Desired_Avg As Double 





    ' Number of clicks that are needed to Achieved desired Avg of clicks over time 
    Clicks_Total = Round(Total_Days * TotalClicksOverTotalDays_Desired_Avg, 0) 

    ' Number of days in which the user has to click atleast once to achieve desired Avg. clicks per day 
    NumDaysToGetClicks = Round(Clicks_Total/ClicksPerDay_Desired_Avg, 0) 

    ' The number of non-click days in order fill out the total days 
    NoClickDays_Total = Round(Total_Days - NumDaysToGetClicks, 0) 





    ' The guessimated average of non-click days per click to fill out total non-click days 
    ' This is never used, just used for comparsion of the running Avg 
    NoClickDaysPerClick_Desired_Avg = NoClickDays_Total/NumDaysToGetClicks 





    'This variable is here to achieved closer results to the desired StdDev. 
    'a higher multiplyer will not limit the deviation but just give an average deviation 
    'For example, if the Average was 3 with a +/- 2, then with a StdDevMulti of 1 
    'ALL numbers will be 1 (3-2) through 5 (3+2) with an avg of 3 and stddev of 2, the numbers will NEVER exceed the StdDev. 
    'With a StdDevMulti of 2, the numbers will be 0 through 6, but should still have an 
    'Avg deviation of 2. 
    StdDevMulti = 1 

    NoClickDays_Desired_Deviation = NoClickDays_Desired_Deviation * StdDevMulti 
    Clicks_Desired_Deviation = Clicks_Desired_Deviation * StdDevMulti 


    'Set the obvious defaults 
    ClickedDaysSoFar = 0 
    Clicks_SoFar = 0 
    NoClickDays_SoFar = 0 

    'Give the ClickOffset a starting value 
    ClickOffset = NoClickDaysPerClick_Desired_Avg 

    Do 

     'used to find the "running" average of days not clicked 
     NoClickDays_Remaining = NoClickDays_Total - NoClickDays_SoFar 

     'used to find the "running" average of clicks per day 
     Clicks_Remaining = (Clicks_Total - Clicks_SoFar) 

     'used in both "running" averages mentioned above and also will 
     'mark the end of the while loop. 
     RemainingClickedDays = (NumDaysToGetClicks - ClickedDaysSoFar) 


     ' Find what the average num. click should be based on the remaining 
     ' and then apply the deviation. Only accept a click below its max 
     ' above its min. 
     Do 

      ' Generate a random number between -1 and 1 
      SignChanger = Rnd() - Rnd() 

      ' Apply the randomized StdDev 
      Clicks_Deviation = Clicks_Desired_Deviation * SignChanger 

      'Figure out the "running" average 
      ClicksPerDay_Running_Avg = Clicks_Remaining/RemainingClickedDays 

      'Figure out a click value and round to the nearest whole number 
      Generated_Clicks = Round(ClicksPerDay_Running_Avg + Clicks_Deviation, 0) 

     ' Make sure it meets the requirements, if not, try again 
     Loop While Generated_Clicks < Clicks_Min Or Generated_Clicks > Clicks_Max 


     ' Set the click value to the spaced-out array index 
     Day_Array(ClickOffset, 1) = Generated_Clicks 


     'Find a random space based upon the "running" avg. and desired deviation 
     'Make sure it between the min and max required. 
     Do 
      ' Generate a random number between -1 and 1 
      SignChanger = Rnd() - Rnd() 

      ' Apply the randomized StdDev 
      NoClickDays_Deviation = NoClickDays_Desired_Deviation * SignChanger 


      'Figure out the "running" average 
      NoClickDaysPerClick_Running_Avg = NoClickDays_Remaining/RemainingClickedDays 

      'Figure out a space value and round to the nearest whole number 
      Generated_NoClickDays = Round(NoClickDaysPerClick_Running_Avg + NoClickDays_Deviation, 0) 

     ' Make sure it meets the requirements, if not, try again 
     Loop While Generated_NoClickDays < NoClickDays_Min Or Generated_NoClickDays >= NoClickDays_Max 



     'Define the array index based upon the spacing previously generated. 
     ' Make sure to "add" upon the already known index. Add 1 because you 
     'have to account for the index the click occupies 
     ClickOffset = ClickOffset + Generated_NoClickDays + 1 




     'These should be self-explaintory 
     ClickedDaysSoFar = ClickedDaysSoFar + 1 
     Clicks_SoFar = Clicks_SoFar + Generated_Clicks 
     NoClickDays_SoFar = NoClickDays_SoFar + Generated_NoClickDays 

    Loop While ClickOffset < Total_Days And RemainingClickedDays > 0 



    'Set the array equal to the clicks so that it returns the array as 
    'we want. Ideally this will be just replace Total_Days fields under 
    'the base, so not to require a array-function. Neither of these work: 
    'ClickSpacer = Range("P1:P" & UBound(Day_Array) + 1).Value 
    'Range("P1:P" & UBound(Day_Array) + 1) = Application.Transpose(Day_Array) 


    ClickSpacer = Day_Array 



End Function 
+1

這裏有很多代碼行已被註釋掉。您的刪除密鑰是否損壞? – 2011-01-10 14:36:21

回答

0

我覺得你的假設是正確的。上面代碼的「問題」在於它使用StdDev作爲生成隨機數的基礎,因此標準偏差將趨於準確,平均值將不準確。

如果你想與平均少用標準差更準確,那麼你就必須要「翻轉」數字是如何產生的:他們需要圍繞着你的期望均值和使用所需的標準偏差一個指南,而不是其他方式。

我如何可以做到這一點的想法,但還需要更多的濃度比我能在工作中使用,所以我必須回來,後來編輯。我會看看我能做什麼。