16

I need to find a polynomial regression line, and I'm using PHP - is there a library or 3rd part script that will do this for me? If it can do ANOVA as well that would be a bonus, but mainly, I need to find regression lines.

I don't know how to calculate a polynomial trend line, and I suspect it would be too difficult for me to learn how to do it myself, so if someone else has a script I'd like to use it. I would also be willing to use another program, that can be called from php (so command line only - no gui) but I would prefer to stick to php.

Benubird
  • 18,551
  • 27
  • 90
  • 141
  • 1
    There's a trend library built into PHPExcel that includes a polynomial best fit class (as well as linear, logarithmic, exponential and power trends). That might give you a starting point. – Mark Baker Feb 25 '11 at 14:54
  • 1
    Have you tried http://www.phpclasses.org/ ? – Raveline Feb 25 '11 at 15:54
  • 1
    There is a stats extension, but I'm not sure if it will do what you need http://us2.php.net/manual/en/book.stats.php – Jeff Busby Feb 25 '11 at 16:17

1 Answers1

6

I would also be willing to use another program, that can be called from php (so command line only - no gui) but I would prefer to stick to php.

I call R from my PHP webpages. RCurl is required. Once you've got R set up you can call your R scripts from PHP via curl().

dnagirl
  • 20,196
  • 13
  • 80
  • 123
  • Do you have an example? RCurl appears to retrieve things over HTTP. How do you use it serve the results from R in a manner that makes them retrievable from PHP? – Rikki Sep 09 '13 at 13:10
  • @Rikki: Have your R script return a JSON object to your PHP script. Then you can do as you like with the object. For larger amounts of data, have your R script write its output to a temporary text file. Return the url of that file to your PHP script. – dnagirl Sep 09 '13 at 13:57
  • but how do you execute the R script? On a cronjob? exec()? – Rikki Sep 10 '13 at 21:15
  • @Rikki This should help http://www.r-bloggers.com/integrating-php-and-r/ – Zero Sep 10 '13 at 22:01
  • @JohnGalt: that's what I was expecting. I don't see how that uses RCurl and does not "call your R scripts from PHP via curl()" (because it's via exec()). The answer is misleading, without an example. – Rikki Sep 12 '13 at 22:11
  • @Rikki: you may need to use RApache (http://rapache.net/) as well. We've got ours set up so it only accepts calls from localhost which helps with security. My sysadmin set that up so I can't really tell you much more about it. – dnagirl Sep 13 '13 at 12:30