Data and plot

x = (runif(5000))
y = x*(1+rnorm(5000,0,0.1))
plot(x,y,cex=.5,pch=21)

mod=lm(y~x)
summary(mod)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.31903 -0.02670  0.00132  0.02686  0.37525 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.002068   0.001679  -1.232    0.218    
## x            1.003865   0.002889 347.520   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.05878 on 4998 degrees of freedom
## Multiple R-squared:  0.9603, Adjusted R-squared:  0.9603 
## F-statistic: 1.208e+05 on 1 and 4998 DF,  p-value: < 2.2e-16
plot(mod)

Examine standard deviation

x_cat=cut(x, breaks = 20)
x_squa=(x)^2
data=data.frame(x,y,x_cat,x_squa)
sd=aggregate(data$y, list(data$x_cat), FUN=sd) 
barplot((sd$x))

Method1, construct a weighted regression using weights proportional to 1/x^2

mod2=lm(y~x,weights=1/x_squa,data=data)
plot(mod2)

## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced

## Warning in sqrt(crit * p * (1 - hh)/hh): NaNs produced

summary(mod2)
## 
## Call:
## lm(formula = y ~ x, data = data, weights = 1/x_squa)
## 
## Weighted Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.37556 -0.06738  0.00033  0.06947  0.42789 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -3.526e-06  2.599e-06  -1.357    0.175    
## x            9.984e-01  1.434e-03 696.460   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1013 on 4998 degrees of freedom
## Multiple R-squared:  0.9898, Adjusted R-squared:  0.9898 
## F-statistic: 4.851e+05 on 1 and 4998 DF,  p-value: < 2.2e-16

Mothod2, Take logs, and fit a linear model with the coefficient restricted to 1 (also called an offset)

log_y=log(y)
log_x=log(x)
plot(x,log_y,cex=.5,pch=21)

plot(log_x,log_y,cex=.5,pch=21)

mod3=lm(log_y~(-1+log_x))
plot(mod3)

summary(mod3)
## 
## Call:
## lm(formula = log_y ~ (-1 + log_x))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.47269 -0.06724  0.00333  0.06937  0.35564 
## 
## Coefficients:
##       Estimate Std. Error t value Pr(>|t|)    
## log_x 1.004546   0.001044   962.7   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1031 on 4999 degrees of freedom
## Multiple R-squared:  0.9946, Adjusted R-squared:  0.9946 
## F-statistic: 9.267e+05 on 1 and 4999 DF,  p-value: < 2.2e-16

References

[https://stats.stackexchange.com/questions/156654/fit-regression-model-from-a-fan-shaped-relation-in-r] [https://www.itl.nist.gov/div898/handbook/pri/section2/pri24.htm]