[R] lm with data=(means,sds,ns)

kjetil@entelnet.bo kjetil at entelnet.bo
Sun Apr 18 14:55:01 CEST 2004


On 18 Apr 2004 at 2:27, Ted Harding wrote:

> Hi Folks,
> 
> I am dealing with data which have been presented as
> 
>   at each x_i, mean m_i of the y-values at x_i,
>                sd s_i of the y-values at x_i
>                number n_i of the y-values at x_i
> 
> and I want to linearly regress y on x.

You need weighted regresseion, so lm with the argument weights. 
Assuning constant variance of the errors, you can calculate
w[i] <-  n_i

and put mean m_i of the y-values at x_i into y,
x_i values into x, n)- values into n. Then

lm(y ~ x, weight=n)

Kjetil Halvorsen

> 
> There does not seem to be an option to 'lm' which can
> deal with such data directly, though the regression
> problem could be algebraically expressed in these terms.
> 
> One way of fudging it would be to replace each m_i by
> a set  of n_i numbers Y_i constructed as
> 
>   u_i <- rnorm(ni)
> 
>   Y_i <- m_i + s_i*(u_i - mean(u_i))/sd(u_i)
> 
> and associate these with X_i <- rep(x_i,n_i), thereby
> constructing a regression-equivalent set of pseudo "raw data"
> which could be fed to lm(Y~X). However, this strikes me as
> cumbersome, at least, and even ugly!
> 
> Is there a direct way to go from {(n_i,m_i,s_i)} to the
> fitted regression, with summaries and all (and use of 'predict')?
> 
> With thanks,
> Ted.
> 
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44
> (0)870 167 1972 Date: 18-Apr-04                                  
> Time: 02:27:50 ------------------------------ XFMail
> ------------------------------
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list