title: Simple Iterative Least Square Algorithms with two unknown variables in the same equation
body: <p>Simple Iterative Least Square Algorithms with two unknown variables in the same equation</p>
  
  <p>Given Equation (1) and data with variables y, d and m, I want to estimate α(αis between 0 and 1) through iterative square approach because β  in Equation (2) also contains the unknown estimate α
              log(y)=c-βlog⁡(d+2αm/(1-α))
  Where<br>
              2)        β=2/(1-α)</p>
  
  <p>Steps for solving Iterative Square approach algorithms are,
      Starts with an initial guess of  α,e.g.,(α_0).
      Regress (1) with initial(α_0)  in place to get the parameter estimate β that is used to calculate a new (α_1).
      Use estimate βon (2) to calculate a new (α_1)
      Use α_1as the “new guess” and repeat steps 2 and 3 until the initial and new αconverge.</p>
  
  <p>I develop the following R-code that follows the 4 steps. However, I would like to loop in steps 2 and 3 and stop the process after convergence (or near convergence-a little tolerance lance levels) </p>
  
  <p>Data link.</p>
  
  <p><a href="https://www.dropbox.com/sh/luhfcwyfuqousfb/AACOtOEddEDDnzBYsguQhkMGa?dl=0" rel="nofollow">https://www.dropbox.com/sh/luhfcwyfuqousfb/AACOtOEddEDDnzBYsguQhkMGa?dl=0</a> </p>
  
  <pre><code>#Clear working directory
  # rm(list=ls()) 
  # Set/Load  working directory
  #setwd("C:\\Users\\Philipmunyua\\Google Drive\\nanoHUB research\\02 analysis\\04 develop level _test spatial\\02 input data")
  # Generating alpha and model distribution
  dat&lt;-read.csv("t06_deg_freq.csv")
  dat$X&lt;-NULL
  dat$ln_deg&lt;-log(dat$degree)
  dat$ln_freq&lt;-log(dat$Freq)
  summary(dat)
  a&lt;-0.98
  a1&lt;-range(0.000,1.000)
  m&lt;-(weighted.mean(dat$degree, dat$Freq)*0.5)
  d&lt;-as.matrix(dat$degree)
  fd&lt;-as.matrix(dat$Freq)
  xd&lt;-as.matrix(dat$degree+((2*m*a)/(1-a)))
  y&lt;-log(fd)
  x&lt;-log(xd)
  fit &lt;- lm(y ~ x, data=dat)
  #summary(fit) # show results
  b.fit&lt;-coef(fit)
  b&lt;-b.fit[2]
  t&lt;-((b-2)/b)
  a1&lt;-ifelse(t&gt;max(a1),max(a1),t)
  </code></pre>