Untitled
unknown
r
2 years ago
2.0 kB
3
Indexable
library(ggplot2) weather <- read.csv("Data/weather.csv") (Y.model <-lm(rain ~pressure, data = weather)) ggplot(data = weather, aes(x = pressure, y = rain)) + geom_point(size = 1) + geom_line(aes(y = Y.model$coefficients[1]+pressure*Y.model$coefficients[2]), linetype = "dashed")+ labs(title = "Precipitation (mm) against Air Pressure (hPa)") # Exponential decay #INTE FÄRDIGT, cbind(BLANK) ska va ngt annat, körde Y.data, men existerar ej. Y.pred <- cbind(BLANK, fit = predict(Y.model), conf = predict(Y.model, interval = "confidence"), pred = predict(Y.model, interval = "prediction")) head(Y.pred) # get rid of the extra fits Y.pred$conf.fit <- Y.pred$pred.fit <- NULL head(Y.pred) Y.pred$e <- Y.model$residuals head(Y.pred) (max.e <- max(abs(Y.pred$e))) (Y.elims <- c(-max.e, max.e)) ## Plot against yhat#### # Add a horizontal line at y=0, # and expand the y-axis to include +/- max residual. ggplot(data = Y.pred, aes(x = fit, y = e)) + geom_point(size = 3) + geom_hline(yintercept = 0) + expand_limits(y = Y.elims) + xlab("Predicted weight loss (g)") + ylab("Residual") + labs(tag = "B") + labs(title = "Residuals vs predicted values Y-hat") + theme(text = element_text(size = 18)) (Ylog.model <-lm(log(rain) ~pressure, data = weather)) ggplot(data = weather, aes(x = pressure, y = log(rain))) + geom_point(size = 1) + geom_line(aes(y = Ylog.model$coefficients[1] +pressure*Ylog.model$coefficients[2]), linetype = "dashed")+ labs(title = "Precipitation (log(mm)) against Air Pressure (hPa)") # Linear to the left, but after 1010 hPa the data seems to have another slope (Ycr.model <- lm(rain^(1/3) ~ pressure, data = weather)) ggplot(data = weather, aes(x = pressure, y = rain^(1/3))) + geom_point(size = 1) + geom_line(aes(y = Ycr.model$coefficients[1] +pressure*Ycr.model$coefficients[2]), linetype = "dashed")+ labs(title = "Precipitation ((mm)^1/3) Against Air Pressure (hPa)") # Linear, fits our model Y = xB + e
Editor is loading...