cking
June 11, 2022, 2:59am
1
Hey can anyone help me with this trend line? Why is it not fitting the data? Thanks
Fish$log.Weight <- log10(Fish$Weight)
Fish$log.Width <- log10(Fish$Width)
fish.lm <- lm(log.Weight ~ log.Width, Fish)
qqplot:
plot(fish.lm, which =2, las=1)
histogram
hist(resid(fish.lm), main = "Residuals", las=1)
summary(fish.lm)
plot(log.Weight~log.Width, data=Fish, pch=16, las=1,
xlab=expression(paste("log.Width", (cm))),
ylab="log.Weight (g)", log="xy")
#add the regression line from the fitted model:
abline(fish.lm, col='blue')
FJCC
June 11, 2022, 3:36am
2
Using the axes to a log scale seems to be the problem. Here are some plots with data I invented.
DF <- data.frame(Width=2:50)
DF$Weight <- DF$Width*4.32
DF$log.Weight <- log10(DF$Weight)
DF$log.Width <- log10(DF$Width)
FIT <- lm(log.Weight~log.Width,data=DF)
FIT2 <- lm(log10(log.Weight)~log10(log.Width),data=DF)
plot(log.Weight~log.Width,data=DF,log="xy")
abline(FIT)
abline(FIT2,col="red")
plot(log.Weight~log.Width,data=DF)
abline(FIT)
Created on 2022-06-10 by the reprex package (v2.0.1)
cking
June 11, 2022, 4:58am
3
Thanks for your help! just with FIT2 - am I then taking a log of a log?
How would I predict values of weight with this line?
The solution here is to use untf=TRUE for abline param when you are using the log="xy" scale.
If untf is true, and one or both axes are log-transformed, then a curve is drawn corresponding to a line in original coordinates, otherwise a line is drawn in the transformed coordinate system. The h and v parameters always refer to original coordinates.
plot(log.Weight~log.Width,data=DF,log="xy")
abline(FIT,col="blue",untf = TRUE)
2 Likes
system
Closed
June 18, 2022, 8:35am
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.