|
Post by meerkat on May 20, 2018 18:08:07 GMT -5
As a LB beginner, I'm not sure this is the best way to write this program. It's a program I wrote years ago in Run Basic. This program finds the coefficients of a multiple variable linear equation using the method of least squares. The equation is of the following form: r = c + a 1x1 + a2x2 + ... anxnWhere x = dependent variable c = constanta1,a2 ...,an = coefficients of independent variable x1,x2....,xnYou provide a CSV file where the first variables are the independent and the last variable is the dependent. You specify the look of the CSV, and include a header if desired. Sample csv: 'age','grade','height','weight' '5','8','48','59' '11','9','49','55' '6','6','44','50' '12','10','59','80' '4','8','55','61' '3','9','51','75' '4','9','55','67' '8','7','50','58' Knowing the independent age, grade, and height of a person, the program will try to determine the dependent weight. DownloadAttachments:mlr.bas (9.53 KB)
|
|
|
Post by Gordon Rahman on May 21, 2018 4:28:12 GMT -5
hmmm... I'm missing the function replace$(a4,b$,c$)
Gordon
|
|
|
Post by meerkat on May 21, 2018 7:06:32 GMT -5
hmmm... I'm missing the function replace$(a4,b$,c$) Interesting! Not sure what's going on. The program at the download location shows: replstr$(a$,b$,c$) not replace$(a$,b$,c$) I know that some LB versions do no support replstr$() so maybe that's the problem. If it does not support replstr$() then add this function to the program.. I'm using LB 4.501 pro ' --------------------------------
' string replace rep str with
' --------------------------------
FUNCTION replstr$(str$,rep$,with$)
ln = len(rep$)
ln1 = ln - 1
i = 1
while i <= len(str$)
if mid$(str$,i,ln) = rep$ then
replstr$ = replstr$ + with$
i = i + ln1
else
replstr$ = replstr$ + mid$(str$,i,1)
end if
i = i + 1
WEND
END FUNCTION
|
|
|
Post by tsh73 on May 21, 2018 7:15:08 GMT -5
I believe it's newer LB 4.5.1 function.
EDIT oh, sure,
replstr$(source$, old$, new$)
|
|
|
Post by tenochtitlanuk on May 21, 2018 7:57:38 GMT -5
Interesting prog- I always intended to write one for this topic. Have you looked at Rosetta Code? There is no entry yet for Multiple Linear Reg'n for LB. Perhaps you could submit a cut-down version? Like the GUI interface, and ability to select separators/delimiters. You could presumably automate that ability.
|
|
|
Post by Gordon Rahman on May 21, 2018 9:14:45 GMT -5
Hello tsh73 Oops, could be my fault. I did a run from the download ... and maybe my LB version was 4.04 at that instance I tried it again in LB 4.5.1 without the extra function listing ..... and it works ... Now I had to find an error ..... Ok .... The trapclose sends you to a not existing label [exit] ... the label should be [expExt] Gordon
|
|
|
Post by meerkat on May 21, 2018 10:02:03 GMT -5
Have you looked at Rosetta Code? There is no entry yet for Multiple Linear Reg'n for LB. Perhaps you could submit a cut-down version? No.. Have not looked at Rosetta Code. I'm making changes to the ionSQL program. Right now you can export a table to CSV. I'm making changes to match the Run Basic version where you can specify the columns to export and their order. This will then give you the ability to export table information needed for MLR. Give it a day or two before trying the new download of ionSQL with the additions. I'll have a look after the ionSQL changes. Thanks Gordon for the trap close error. This is my 2nd LB program, so I'm still in learning mode. The program is hard to verify.. So any errors or comments are welcome.
|
|
|
Post by meerkat on May 22, 2018 9:14:28 GMT -5
OK! Changed the ionSQL program so that you can select the fields and order wanted when exporting to CSV. This will let you put the dependent variable at the end. You can maintain your table of information for whatever with ionSQL. I've tested the MLR to increase output on a production line by monitoring various variables such as voltage, speed of certain areas and reject rate. Been able to zero in somewhat on what was causing rejects on the line. I tried to find out what makes a stock go up or down.. I know this is not possible but fun try... Download ionSQL and MLR from Here Haven't had time to test it completely, but since I will be out of town for a week, decided to publish it.. Good luck.. Dan
|
|
|
Post by mpranger on Nov 20, 2020 19:17:00 GMT -5
Did you ever get a version of this up and running correctly? This is really a cool idea.
|
|
|
Post by tsh73 on Nov 21, 2020 10:04:59 GMT -5
I have no idea about "correctly" but line "Download ionSQL and MLR from Here" contains a link from "Here" to www.kneware.com/libertybasic/I loaded content of mlr/ folder, and it runs in LB 5.4.1 OK
|
|