1
$\begingroup$

Please take a look at the below code: temperature.txt:

time temperature
0 100
1 82
2 60
3 50
4 40
5 32
6 28
7 20
data <- read.table(file = "temperature.txt", header = TRUE)

plot(data$time, data$temperature, xlab="time", ylab="temperature")

abline(lm(data$temperature ~ data$time))

Add the regression line.

Here, another fit with the code:

b = (length(data$time)*sum(log(data$time + 1)*data$temperature) -  
    sum(data$time + 
    1)*sum(data$temperature))/(length(data$time)*sum(log((data$time + 
    1)^2)) - (sum(log(data$time + 1)))^2)

a = sum(data$temperature)/length(data$time) - 
    b/length(data$time)*sum(data$time)

the line should be:

y=a+b*log(data$time+1)  

change to dataframe style

add1 <- data.frame(time=c(0:7), temperature=c(y))   

Now, compare with these two fit line with graph:

par(mfrow=c(1,2))

the first fit method

plot(data$time, data$temperature, xlab="time", ylab="temperature")

abline(lm(data$temperature ~ data$time))

the second fit method

plot(add1$time, add1$temperature, xlab="time", ylab="temperature")

abline(lm(add1$temperature ~ add1$time))

the graph below:

enter image description here

Since I am not good at the theorem of some statistics. I would like to know which method is a better fit, as the graph looks similar.

$\endgroup$
2
  • 1
    $\begingroup$ welcome to CV. The y values are different between the two graphs so the model isn't quite right. From your comments the graph on the right is a fitted model on the data plotted on the left. Are you wanting compare the fit of that model (y=a+b*log(dataStime+1)) to the actual data? If so generate the trendline from your model and overlay on the data. You can assess fit in a few ways such as the residual variation after you subtract the predictions of proposed model from the actual data, often expressed as $R^2$. There are other metrics depending on your needs. $\endgroup$
    – ReneBt
    Oct 14 at 5:34
  • $\begingroup$ Thanks a lot. Gotcha! $\endgroup$
    – itchy cat
    Oct 14 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.