How do I perform power regression in R?

Power regression in R can be performed by using the lm() function, which fits a linear model to the data. The model is specified by using the formula argument, where the independent variable is raised to a power. This is done by including the ^ operator and the desired power value in the formula. Once the model is specified, the lm() function is used to fit the data and to generate the coefficients and other summary statistics such as the R-squared and F-statistic.


Power regression is a type of non-linear regression that takes on the following form:

y = axb

where:

  • y: The response variable
  • x: The predictor variable
  • a, b: The regression coefficients that describe the relationship between x and y

This type of regression is used to model situations where the is equal to the predictor variable raised to a power.

The following step-by-step example shows how to perform power regression for a given dataset in R.

Step 1: Create the Data

First, let’s create some fake data for two variables: x and y.

#create data
x=1:20
y=c(1, 8, 5, 7, 6, 20, 15, 19, 23, 37, 33, 38, 49, 50, 56, 52, 70, 89, 97, 115) 

Step 2: Visualize the Data

Next, let’s create a scatterplot to visualize the relationship between x and y:

#create scatterplot
plot(x, y)

From the plot we can see that there exists a clear power relationship between the two variables. Thus, it seems like a good idea to fit a power regression equation to the data instead of a linear regression model.

Step 3: Fit the Power Regression Model

Next, we’ll use the lm() function to fit a regression model to the data, specifying that R should use the log of the response variable and the log of the predictor variable when fitting the model:

#fit the model
model <- lm(log(y)~ log(x))

#view the output of the model
summary(model)

Call:
lm(formula = log(y) ~ log(x))

Residuals:
     Min       1Q   Median       3Q      Max 
-0.67014 -0.17190 -0.05341  0.16343  0.93186 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.15333    0.20332   0.754    0.461    
log(x)       1.43439    0.08996  15.945 4.62e-12 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3187 on 18 degrees of freedom
Multiple R-squared:  0.9339,	Adjusted R-squared:  0.9302 
F-statistic: 254.2 on 1 and 18 DF,  p-value: 4.619e-12

Using the coefficients from the output table, we can see that the fitted power regression equation is:

ln(y) = 0.15333 + 1.43439ln(x)

Applying e to both sides, we can rewrite the equation as:

  • y = e 0.15333 + 1.43439ln(x)
  • y = 1.1657x1.43439

We can use this equation to predict the response variable, y, based on the value of the predictor variable, x.

For example, if x = 12, then we would predict that y would be 41.167:

y = 1.1657(12)1.43439 = 41.167

Bonus: Feel free to use this online to automatically compute the power regression equation for a given predictor and response variable.

x