# Which fit-line below is better in R

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))


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: 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. • 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. Oct 14 at 5:34
• Thanks a lot. Gotcha! Oct 14 at 5:41