title: Variable lengths differ help, lm regression and weights, variables have the same number of rows
body: <p>I'm trying to run a weighted squares regression, after creating my weights and trying to add it to my regression function I receive the following error:</p>
  <blockquote>
  <p>Error in model.frame.default(formula = CO2_pc_cmice1 ~   GDP_pc_cmice1_C +  :<br />
  variable lengths differ (found for '(weights)')</p>
  </blockquote>
  <p>The <code>lm</code> model has 31 rows and the weights I've created are also 31, I've checked to see if there are <code>NA</code>s in either of these and there are not. There are some negative numbers, although I'd be surprised if this was the issue. I've run the formula using both <code>na.action = na.omit</code> and <code>na.action = na.exclude</code></p>
  <p>I'm also running this with a regression with a sample of 99 and I get the same issue.</p>
  <p>My regression is</p>
  <pre><code>LinearCO2_lowerF &lt;- (lm(CO2_pc_cmice1 ~ PolCiv_incPressFreedom_C + CorpInf_cmice1_C + 
                                          Gov_cmicepos1_C + LitGini_umice_C + 
                                          GDP_pc_cmice1_C + PopDensity_cmice1_C + 
                                          TradeOpen_cmice1_C + Urban_cmice1_C +
                                          poly(Oil_coal_umice_C,2), 
                                          data = mydata_completemice2, 
                                          subset = IncomeL == &quot;L&quot;))
  </code></pre>
  <p>Weights created</p>
  <pre><code>wtsco2low &lt;- 1/fitted( lm(abs(residuals(LinearCO2_lowerF))~fitted(LinearCO2_lowerF)) )^2 
  </code></pre>
  <p>And the regression with weights</p>
  <pre><code>LinearCO2_lowerFw &lt;- lm(CO2_pc_cmice1 ~ GDP_pc_cmice1_C + PolCiv_incPressFreedom_C +
                                          CorpInf_cmice1_C + Gov_cmicepos1_C + 
                                          LitGini_umice_C + PopDensity_cmice1_C +
                                          TradeOpen_cmice1_C + Urban_cmice1_C + 
                                          poly(Oil_coal_umice_C,2), 
                                          data = mydata_completemice2, 
                                          subset = IncomeL == &quot;L&quot;,
                                          weights = wtsco2low, 
                                          na.action = na.omit)
  </code></pre>
  <p>(Have also tried with <code>na.exlude</code>)</p>
  <p>Is anyone able to help?</p>