468,727 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

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.,basically 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
Feb 12 '08 #1
7 15060
kadghar
1,295 Expert 1GB
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.,basically 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.
Feb 12 '08 #2
Killer42
8,435 Expert 8TB
Yes, try here .
Feb 12 '08 #3
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..thanx..x
Feb 12 '08 #4
kadghar
1,295 Expert 1GB
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..thanx..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:

Expand|Select|Wrap|Line Numbers
  1. sub var()
  2. dim i as long
  3. dim a as double
  4. dim b as double
  5. for i = 1 to 10
  6.     a= a + cells(i,1)
  7. next
  8. a=a/10 'now a is the mean
  9. for i = 1 to 10
  10.     b = b+ (cells(i,1)-a)^2
  11. next
  12. b= b/9 'and b is the variance
  13. cells(1,2) = b 'write it in the cell B1
  14. end sub
Please, give it a try by your self.

Kad
Feb 12 '08 #5
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:

Expand|Select|Wrap|Line Numbers
  1. sub var()
  2. dim i as long
  3. dim a as double
  4. dim b as double
  5. for i = 1 to 10
  6.     a= a + cells(i,1)
  7. next
  8. a=a/10 'now a is the mean
  9. for i = 1 to 10
  10.     b = b+ (cells(i,1)-a)^2
  11. next
  12. b= b/9 'and b is the variance
  13. cells(1,2) = b 'write it in the cell B1
  14. end sub
Please, give it a try by your self.

Kad
Hi Kad..i know am being a bad girl...lol...and 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
Feb 13 '08 #6
kadghar
1,295 Expert 1GB
Hi Kad..i know am being a bad girl...lol...and 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.
Feb 13 '08 #7
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...Thanx 4 ur time..x
Feb 13 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by nikie | last post: by
3 posts views Thread by sql guy123 | last post: by
1 post views Thread by wirecom | last post: by
1 post views Thread by benjamin.d.rogers | last post: by
1 post views Thread by Nod Lee | last post: by
3 posts views Thread by ntuyen01 | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.