Hello, I am using R, through rsruby, to create a graph and best fit line for a set of data points, regarding data collected in a Chemistry class. The problem is that although the graph functions perfectly properly, the best fit line will not work.
I initially used code I pretty much copied from a website with a tutorial on this, which was: graphData.png("/code/Beer's-Law Graph.png") concentration = p1Conc absorbance = p1AbsorbanceArray graphData.assign('x', p1Conc) graphData.assign('y', p1AbsorbanceArray) fit = graphData.lm('x ~ y') graphData.plot(concentration, absorbance) graphData.abline(fit["coefficients"]["(Intercept)"], fit["coefficients"]["y"]) puts fit["coefficients"] graphData.eval_R("dev.off()") (p1Conc and p1AbsorbanceArray are arrays) This worked for the graph, but the best fit line looked (and the infinitesimally small slope supported) like it was based off a single point. The site said they had to define something in the R interpreter first, but didn't elaborate, so I gave it a go, and obviously it didn't work. I then tried something like this, as I thought the conversion from the array to the string in the assign function was causing the problem with the best fit line. graphData = RSRuby.instance graphData.png("/code/Beer's-Law Graph.png") concentration = graphData.c(p1Conc[0..(p1SampNum - 1)]) absorbance = graphData.c(p1AbsorbanceArray[0..(p1SampNum - 1)]) fit = graphData.lm(concentration ~ absorbance) graphData.plot(concentration, absorbance) graphData.abline(fit["coefficients"]["(Intercept)"], fit["coefficients"][absorbance]) puts fit["coefficients"] print "\n" graphData.eval_R("dev.off()") Basically trying to bypass that, and feed the numbers straight from the array into the best fit line, but the program was giving me an error, saying it didn't know what ~ was for an array (should note I tried it first without doing the graphData.c thing, but that didn't work and as the .c function didn't seem to store things as an array, I thought that might work, it didn't, as it does store data as an array). So basically I'm stuck. Not sure if anyone has any experience with rsruby, but any help would be appreciated. I'm pretty sure the fit = graphData.lm(etcetera) line is where the trouble is, but not sure how to handle it. -- View this message in context: http://r.789695.n4.nabble.com/Best-Fit-line-trouble-with-rsruby-tp3026437p3026437.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.