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

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

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 in… 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?

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 coefficients… Read More How to add coefficients to existing data base such that their effect on the final intercept is given?

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

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, 2nd… 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?

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’ data.frame/tibble… Read More is the `names_sep` argument in `tidyr::pivot_longer` flexible on string splitting?