From jsignoro at hsph.harvard.edu  Thu Jun 22 21:38:30 2006
From: jsignoro at hsph.harvard.edu (jsignoro at hsph.harvard.edu)
Date: Thu, 22 Jun 2006 21:38:30 +0200 (CEST)
Subject: [Rd] weights in lm, glm (PR#9023)
Message-ID: <20060622193830.B53FF19A72@slim.kubism.ku.dk>

Full_Name: James Signorovitch
Version: 2.2.1
OS: WinXP
Submission from: (NULL) (134.174.182.203)


In the code below, fn1() and fn2() fail with the messages given in the comments.
 Strangely, fn2() fails for all data sets I've tried except for those with 100
rows.  
The same errors occur if glm() is used in place of lm(), or if R 2.1.1 is used
on a unix system.  Thanks for looking into this.  JS 

fn1 <- function(model, data)
{
	w <- runif(nrow(data));
	print(lm(model, data=data, weights=w));		
}

fn2 <- function(model, data)
{
	print(lm(model, data=data, weights=runif(nrow(data))));	
}

n = 101;

A <- data.frame(matrix(rnorm(2*n), n, 2));
names(A) <- c("x", "y");

# we can run the command
print(lm(y ~ x, data=A, weights=runif(nrow(A))));

# But fn1() generates the error message
# 
# Error in eval(expr, envir, enclos) : object "w" not found
#

fn1(y ~ x, data=A);

# fn2() generates the error message:
# Error in model.frame(formula, rownames, variables, varnames, extras,
extranames,  : 
#       variable lengths differ
#
#
# But fn2() works if n=100

fn2(y ~ x, data=A);

# note: the error in fn1() still occurs if w <- 1:nrow(data);



[Rd] weights in lm, glm (PR#9023)
jsignoro at hsph.harvard.edu