# Polynomial regression models return different values: `lm(dist ~ speed+I(speed^2), data=cars)` and `lm(dist ~ poly(speed, degree = 2), data = cars)`

Advertisements Using the cars data in R, I would like to create a polynomial regression model with varying degree values. Through research online I have found two methods of creating these models: library(tidyverse) data(cars) # method 1 polyreg_deg2 <- lm(dist ~ speed+I(speed^2), data=cars) # method 2 polyreg_deg2_again <- lm(dist ~ poly(speed, degree = 2), data… Read More Polynomial regression models return different values: `lm(dist ~ speed+I(speed^2), data=cars)` and `lm(dist ~ poly(speed, degree = 2), data = cars)`

# R: apply regression's model parameters at another spatial scale

Advertisements I have three raster layers, two coarse resolution and one fine resolution. I perform simple linear regression using the coarse resolution rasters and then I extract the coefficients of the regression (slope and intercept) and I use them with my fine resolution raster. So far, I am doing this manually by plotting the coefficients… Read More R: apply regression's model parameters at another spatial scale

# How to add coefficients to existing data base such that their effect on the final intercept is given?

Advertisements Firstly, let’s say I have a data frame df with variables y, x1, x2, x1 is a continuous variable and x2 is a factor. Let’s say I have a model: model <- glm(y ~ x1 + x2, data = df, family = binomial) This will result in an object where I can extract the… Read More How to add coefficients to existing data base such that their effect on the final intercept is given?

# How to get coefficients from a model in R?

Advertisements I am trying to store coefficients from a mle model just like a normally do for other models. Surprisingly, it throws an error. Any other methods to store it? set.seed(111) y.size <- rnorm(100,4,1) p <- rnorm(100,5,1) df <- data.frame(p, y.size) glae <- function(A,K,Ka,q, sigma, c) { lnqp <- if(q == 0) log(p) else ((p^q… Read More How to get coefficients from a model in R?

# How do I use the means of the columns of a matrix as prediction values in a linear regression in R?

Advertisements Problem Statement: Some near infrared spectra on 60 samples of gasoline and corresponding octane numbers can be found by data(gasoline, package="pls"). Compute the mean value for each frequency and predict the response for the best model using the five different methods from Question 4. Note: This is Exercise 11.5 in Linear Models with R,… Read More How do I use the means of the columns of a matrix as prediction values in a linear regression in R?

# is the `names_sep` argument in `tidyr::pivot_longer` flexible on string splitting?

Advertisements I have some random effect coefficients extracted from a R model object. For a random intercept, they look like this: xx <- data.frame( `Estimate.Intercept` = c(-0.1, -0.2), `Est.Error.Intercept` = c(0.7, 0.8), `Q5.Intercept` = c(-1.5, -1.4), `Q95.Intercept` = c(0.7, 0.8) ) I’m formatting the data for a .csv report and trying to generate a ‘long’… Read More is the `names_sep` argument in `tidyr::pivot_longer` flexible on string splitting?

# r.squared matrix of predictions vs actual values in R

Advertisements I want to create a matrix that displays the r.squared coefficient of determination of some predictions made over the years and the actual values. My goal is to display a matrix that looks something like this. The only way I found is to make multiple lists, calculate each row/ column individually using map2_dbl(l.predicted_line1, l.actual,… Read More r.squared matrix of predictions vs actual values in R