2011-01-10 3 views
0

(평균, StdDev..etc) 모방 : 그 질문은 내가 후에 누구인지 설명 할 것이다 Excel Generate Normalized DataVBA : 생성 데이터 특정 매개 변수 내가 여기 나에게 주어진 VBA 배열 기능을 수정 한

합니다. I가 사용하고


다운로드 엑셀 완전히 이해 :

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


나는 다음과 같은 데이터를 사용하고 (왼쪽 데이터베이스가하는 I 입력 값입니다 , 오른쪽은 생성 된 데이터의 결과입니다.) :

alt text

보시다시피 평균 차이는 % 클릭에 대해 매우 좋지만 클릭률/시간은 높은 날 표준 (Day +/-) 일 때 꺼져 있습니다. 낮은 날 STDDEV이 차이가 나는 (실행 평균을 결정하는 데 간접적으로 사용된다)를 NoClickDays_Total는 "추측"되기 때문에 VAR NoClickDaysPerClick_Running_Avg가 부정확되기 때문이라고 생각 0

에 가까운 처음에는 높은 StdDev가 임의성을 추가하고 원래의 "추측"이 점점 더 부정확 해지기 때문에 각 클릭을 재평가해야합니다.

이것이 문제인지 확실하지 않거나 해결할 수있는 방법인지 잘 모르겠습니다.

나는 내가 원하는 것을하기위한 최선의 방법에 대한 조언을 찾고있다. stdDev가 너무 멀리 떨어져 있지만 왜 그렇게 큰일인지는 잘 모르겠습니다. 나는 StdDev의 날이 무엇인지에 관계없이, 다른 어떤 것보다 더 정확한 클릭/시간을 갖고 싶습니다. 나는 당신의 가정이 올바른 생각

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

여기에 주석 처리 된 코드 줄이 많이 있습니다. 삭제 키가 손상 되었습니까? –

+0

죄송합니다. Dim 변수가 많이 있지만 Dim은 함수 매개 변수로 정의 되었기 때문에 주석 처리되었지만 주석이 달려있어 정의되어 있고 모든 것이 정의 된 곳이 1 개 있습니다 (모든 것이 Dim으로 정의 된 것은 아닙니다.) 아직 ... 그 WIP) – ParoX

+0

하지만 왜 독자들은 여기를 지나치게 지나치게 소음과 과도한 공백을 겪게합니까? 스크롤바는 좋은 징조가 아닙니다 ...! – Arjan

답변

0

: 여기


내 VBA의 기능입니다. 위의 코드에서 "문제"는 난수 생성을위한 표준으로 StdDev를 사용하므로 표준 편차가 정확하고 평균이 덜 정확합니다.

표준 편차로 평균과 더 적은 정확도를 원하는 경우 숫자 생성 방법을 "뒤집어"해야합니다. 원하는 평균을 중심으로 원하는 표준 편차를 사용해야합니다. 가이드가 아닌 다른 방향으로 안내합니다.

어떻게 할 수 있는가에 대한 아이디어가 있지만 직장에서 적용 할 수있는 것보다 집중해야하므로 나중에 다시 돌아와서 편집해야 할 것입니다. 내가 무엇을 할 수 있는지 알아볼 게.