Linear regression code in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PlsHelp
    New Member
    • Feb 2008
    • 4

    Linear regression code in VB

    Hi every1,this is my 1st time using this forum....pls can any1 tell me how to create a code in VB that can do LINEAR REGRESSION in excel.....i'm not sure how to xplain exactly what i need but basically you know when u use the data analysis tool for regression in excel and it outputs the intercept,anova ,residuals e.t.c.,basicall y i need to be able to do a code in VB that can calculate all dis(linear regression) using the data that i have and output the result in2 excel.
    PLS if any1 knows how to do this pls pls reply me asap...am at my wits end....Thanx... x
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by PlsHelp
    Hi every1,this is my 1st time using this forum....pls can any1 tell me how to create a code in VB that can do LINEAR REGRESSION in excel.....i'm not sure how to xplain exactly what i need but basically you know when u use the data analysis tool for regression in excel and it outputs the intercept,anova ,residuals e.t.c.,basicall y i need to be able to do a code in VB that can calculate all dis(linear regression) using the data that i have and output the result in2 excel.
    PLS if any1 knows how to do this pls pls reply me asap...am at my wits end....Thanx... x
    Do you need the code to get this result using the excel's Linear Regression?? then just use the Macro Recorder.
    If what you want is to program each function, well, i think it's going to take you a little bit more time, but you can find all the formulas and algorithms in wikipedia, in case you need them.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Yes, try here .

      Comment

      • PlsHelp
        New Member
        • Feb 2008
        • 4

        #4
        Hi thanx 4 d reply,i was going 2 use the macro recorder but i'm not allowed to,i'll av 2 write d code from start myself and thats where i'm stuck,i've tried wikipedia but i havent had much help from dat either as i'm not able 2 apply d formulas in2 writing a code but i'm giving it a try....pls any more help would b appreciated..th anx..x

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          Originally posted by PlsHelp
          Hi thanx 4 d reply,i was going 2 use the macro recorder but i'm not allowed to,i'll av 2 write d code from start myself and thats where i'm stuck,i've tried wikipedia but i havent had much help from dat either as i'm not able 2 apply d formulas in2 writing a code but i'm giving it a try....pls any more help would b appreciated..th anx..x
          Here's a little example to calculate the variance of A1:A10... we're not supposed to help you in your homework, it's for you to learn, but i think this might point you in the right direction:

          [CODE=vb]sub var()
          dim i as long
          dim a as double
          dim b as double
          for i = 1 to 10
          a= a + cells(i,1)
          next
          a=a/10 'now a is the mean
          for i = 1 to 10
          b = b+ (cells(i,1)-a)^2
          next
          b= b/9 'and b is the variance
          cells(1,2) = b 'write it in the cell B1
          end sub[/CODE]

          Please, give it a try by your self.

          Kad
          Last edited by kadghar; Feb 12 '08, 11:46 PM. Reason: variable error

          Comment

          • PlsHelp
            New Member
            • Feb 2008
            • 4

            #6
            Originally posted by kadghar
            Here's a little example to calculate the variance of A1:A10... we're not supposed to help you in your homework, it's for you to learn, but i think this might point you in the right direction:

            [CODE=vb]sub var()
            dim i as long
            dim a as double
            dim b as double
            for i = 1 to 10
            a= a + cells(i,1)
            next
            a=a/10 'now a is the mean
            for i = 1 to 10
            b = b+ (cells(i,1)-a)^2
            next
            b= b/9 'and b is the variance
            cells(1,2) = b 'write it in the cell B1
            end sub[/CODE]

            Please, give it a try by your self.

            Kad
            Hi Kad..i know am being a bad girl...lol...an d i'm not supposed 2 get help but i only need a push in d right direction and i'll be able to take it from there..cos i've neva done VB b4 and i've jst been kinda pushed in2 it and i'm faced with a lot of obstacles.....i fink i shud b able 2 giv it a go now from ur help...thanx a lot....really sorry if i offeded any1...x

            Comment

            • kadghar
              Recognized Expert Top Contributor
              • Apr 2007
              • 1302

              #7
              Originally posted by PlsHelp
              Hi Kad..i know am being a bad girl...lol...an d i'm not supposed 2 get help but i only need a push in d right direction and i'll be able to take it from there..cos i've neva done VB b4 and i've jst been kinda pushed in2 it and i'm faced with a lot of obstacles.....i fink i shud b able 2 giv it a go now from ur help...thanx a lot....really sorry if i offeded any1...x
              bad girl Ô_o ... hmm .... pushed into it???

              VB is a nice language, many do it for living. Search some tutorials in google about functions and how to use Excel's VBA. If you have more particular doubts about how tu make something work in a function, or how to have the right results in your excel's sheet, we'll be glad to help you in your future tasks.

              Comment

              • PlsHelp
                New Member
                • Feb 2008
                • 4

                #8
                Originally posted by kadghar
                bad girl Ô_o ... hmm .... pushed into it???

                VB is a nice language, many do it for living. Search some tutorials in google about functions and how to use Excel's VBA. If you have more particular doubts about how tu make something work in a function, or how to have the right results in your excel's sheet, we'll be glad to help you in your future tasks.
                Thanx....i didnt mean any offence to any1....hope we're cool....lol...i 'll take ur advice on board especially what u gave me earlier and i'll holla if i have any more problems...Than x 4 ur time..x

                Comment

                Working...