Trendline and given Equation

greetings all. So, I'm really new to R. I'm using heat capacity data, to determine which of two amino acids has the larger entropy. I've been able to do this in excel, in no time. But, trying to do the same in R has posed... issues. I'm easily 9-10hrs into trying to figure it out on the fly.

I've had successes in displaying the equation, however, the given variables are either 1) incorrect or 2) i don't know how to correctly interpret the data.

I really, really don't know what i'm doing. Everything i've done up to this point is trying to replicate the processes from excel into R, by googling how-to concepts along the way.

  1. graph data
  2. find equation for graph
    ----- steps 3 and 4 i could do outside of the program, if needed.
  3. use equation to integrate S(T) =∫_(T initial)^(T final)▒〖((Cp,m)/T〗)dT from a temp of 10 to 300
  4. compare two data sets to see which has a larger S value.

any guidance would be so helpful

Without knowing what the data look like, it is hard to give specific advice. Please provide at least a small subset of your data in a format that is convenient for copying, not an image of the data. There is some advice here

about providing data. If you get tangled up doing that (being new to R), at least type out a few rows of data separated by commas and with no spaces. Then describe what you want to graph and the kind of fit you want to do, e.g. linear fit. With that information, some one can easily help you.

Thank you for the fast, and helpful reply. Here is the data i'm working with:


Scatter plot with a polynomial fit(2nd order, if that matters?) (trendline) where x= Temp y=Cp

in the end, i'm looking for an equation of y=-0.0006x^2+0.5335x-7.5716 R^2 = 0.9905

You can see the fit coefficients in the Estimate column of the summary. You can also get them with the code


after running the lm() function.

Here is my code:

Temp <- c(10,20,30,40,60,80,100,120,140,160,180,200,220,240,260,280,300)
Cp <- c(0.3,2.4,7.0,3.0,25.1,35.2,43.2,50.0,56.0,61.6,67.0,72.2,77.4,82.8,88.4,94.0,99.7)
plot(Temp, Cp)

FIT <- lm(Cp ~ I(Temp^2) + Temp)

#> Call:
#> lm(formula = Cp ~ I(Temp^2) + Temp)
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -9.7764 -1.3967 -0.3365  2.5989  4.0562 
#> Coefficients:
#>               Estimate Std. Error t value Pr(>|t|)    
#> (Intercept) -7.5715948  2.2721831  -3.332  0.00493 ** 
#> I(Temp^2)   -0.0006190  0.0001195  -5.180  0.00014 ***
#> Temp         0.5334586  0.0369039  14.455 8.29e-10 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Residual standard error: 3.535 on 14 degrees of freedom
#> Multiple R-squared:  0.9905, Adjusted R-squared:  0.9891 
#> F-statistic: 726.1 on 2 and 14 DF,  p-value: 7.234e-15

Created on 2019-12-11 by the reprex package (v0.2.1)

1 Like

wow. Thank you, oh so much. You made the many hours i worked at this, seem like a breeze when you did it.

i will say, i was in the correct area for parts. I was using the lm command, but didn't know how to incorporate it like you did.

Don't get discouraged. R is a big change from spreadsheets. I suggest you work at problems to the point of moderate frustration, then ask here or a similar place. Soon, you will get the hang of doing the things you routinely have to do. But you will never run out of things to learn about R.

If your problem is solved, please mark the solution.

Quick question, When i was doing this i got there in a different way. Is it safe to say that there could be other ways to get to this solution? This way seems so easy, but i get the impression R doesn't have one set path to any one answer?

There are almost always many ways to get to the same answer in R. If a method makes sense to you, there is no reason to feel bad about other people using a different approach. As a novice, the variety of methods can be confusing, for sure.

1 Like

Check out the broom package for easy access to modelling stats:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.