Displaying 20 results from an estimated 20000 matches similar to: "Referencing objects within a loop"
2005 Jan 06
2
Generating Data mvrnorm and loops
Dear List:
I am generating N datasets using the following
Sigma<-matrix(c(400,80,80,80,80,400,80,80,80,80,400,80,80,80,80,400),4,4
)
mu<-c(100,150,200,250)
N=100
for(i in 1:N)
{
assign(paste("Data.", i, sep=''),
as.data.frame(cbind(seq(1:1000),(mvrnorm(n=1000, mu, Sigma)))))
}
With these datasets, I need to work on some of the variables and then
run each dataset
2005 Jan 18
4
Data Simulation in R
Dear List:
A few weeks ago I posted some questions regarding data simulation and
received some very helpful comments, thank you. I have modified my code
accordingly and have made some progress.
However, I now am facing a new challenge along similar lines. I am
attempting to simulate 250 datasets and then run the data through a
linear model. I use rm() and gc() as I move along to clean up the
2005 Jan 20
1
Windows Front end-crash error
Dear List:
First, many thanks to those who offered assistance while I constructed
code for the simulation. I think I now have code that resolves most of
the issues I encountered with memory.
While the code works perfectly for smallish datasets with small sample
sizes, it arouses a windows-based error with samples of 5,000 and 250
datasets. The error is a dialogue box with the following:
"R
2005 Jan 08
2
Does R accumulate memory
Dear List:
I am running into a memory issue that I haven't noticed before. I am
running a simulation with all of the code used below. I have increased
my memory to 712mb and have a total of 1 gb on my machine.
What appears to be happening is I run a simulation where I create 1,000
datasets with a sample size of 100. I then run each dataset through a
gls and obtain some estimates.
This works
2006 Oct 31
2
Put a normal curve on plot
I would like to be able to place a normal distribution surrounding the
predicted values at various places on a plot. Below is some toy code
that creates a scatterplot and plots a regression line through the data.
library(MASS)
mu <- c(0,1)
Sigma <- matrix(c(1,.8,.8,1), ncol=2)
set.seed(123)
x <- mvrnorm(50,mu,Sigma)
plot(x)
abline(lm(x[,2] ~ x[,1]))
Say I want to add a normal
2011 Nov 23
2
lines and points in xyplot()
Given the following data, I want a scatterplot with the data points and the predictions from the regression.
Sigma <- matrix(c(1,.6,1,.6), 2)
mu <- c(0,0)
dat <- mvrnorm(5000, mu, Sigma)
x <- dat[,1] * 50 + 200
y <- dat[,2] * 50 + 200
fm <- lm(y ~ x)
### This gives the regression line, but not the data
xyplot(y ~ x,
type = c('g', 'p'),
2004 Dec 29
3
gls model and matrix operations
Dear List:
I am estimating a gls model and am having to make some rather unconventional modifications to handle a particular problem I have identified. My aim is to fit a GLS with an AR1 structure, obtain the variance-covariance matrix (V), modify it as needed given my research problem, and then reestimate the GLS by brute force using matrix operations. All seems to be working almost perfectly,
2004 May 17
3
Fatal Error
Dear List:
When trying to open 1.9.0 this morning, I have the following error:
"Fatal Error: Unable to restore saved data in .Rdata"
I am using Windows 2000.
The program then quits. Do I need to reinstall?
Harold C. Doran
One Massachusetts Avenue, NW ยท Suite 700
Washington, DC 20001-1431
202.336.7075
[[alternative HTML version deleted]]
2005 Nov 16
6
nlme question
I am using the package nlme to fit a simple random effects (variance
components model)
with 3 parameters: overall mean (fixed effect), between subject
variance (random) and
within subject variance (random).
I have 16 subjects with 1-4 obs per subject.
I need a 3x3 variance-covariance matrix that includes all 3 parameters
in order to
compute the variance of a specific linear
2006 Jul 20
2
Timing benefits of mapply() vs. for loop was: Wrap a loop inside a function
List:
Thank you for the replies to my post yesterday. Gabor and Phil also gave
useful replies on how to improve the function by relying on mapply
rather than the explicit for loop. In general, I try and use the family
of apply functions rather than the looping constructs such as for, while
etc as a matter of practice.
However, it seems the mapply function in this case is slower (in terms
of CPU
2011 Jan 22
1
faster mvrnorm alternative
Hello,
does anybody know another faster function for random multivariate normal
variable simulation? I'm using mvrnorm, but as profiling shows, my algorithm
spends approximately 50 % in executing mvrnorm function.
Maybe some of you knows much faster function for multivariate normal
simulation?
I would be very gratefull for advices.
--
View this message in context:
2006 May 22
2
Subset a list
I have a data frame of ~200 columns and ~20,000 rows where each column
consists of binary responses (0,1) and a 9 for missing data. I am
interested in finding the columns for which there are fewer than 100
individuals with responses of 0.
I can use an apply function to generate a table for each column, but I'm
not certain whether I can subset a list based on some criterion as
subset() is
2010 Apr 22
2
Compare two data frames
I wonder if there is a more efficient way to do this task. Suppose I have two data frames, such as
d1 <- data.frame(x = c(1,2,3), y = c(4,5,6), z = c(7,8,9))
d2 <- d1[, c('y', 'x')]
The first dataframe d1 has more variables than d2 and the variable columns are in a different order.
So, what I want to do is compare the two frames on the variables that are common between
2009 Aug 07
1
Gauss-Laguerre using statmod
I believe this may be more related to analysis than it is to R, per se.
Suppose I have the following function that I wish to integrate:
ff <- function(x) pnorm((x - m)/sigma) * dnorm(x, observed, sigma)
Then, given the parameters:
mu <- 300
sigma <- 50
m <- 250
target <- 200
sigma_i <- 50
I can use the function integrate as:
> integrate(ff, lower= -Inf, upper=target)
2003 Jun 25
2
within group variance of the coeficients in LME
Dear listers,
I can't find the variance or se of the coefficients in a multilevel model
using lme.
I want to calculate a Chi square test statistics for the variability of the
coefficients across levels. I have a simple 2-level problem, where I want to
check weather a certain covariate varies across level 2 units. Pinheiro
Bates suggest just looking at the intervals or doing a rather
2006 May 20
5
Can lmer() fit a multilevel model embedded in a regression?
I would like to fit a hierarchical regression model from Witte et al.
(1994; see reference below). It's a logistic regression of a health
outcome on quntities of food intake; the linear predictor has the form,
X*beta + W*gamma,
where X is a matrix of consumption of 82 foods (i.e., the rows of X
represent people in the study, the columns represent different foods,
and X_ij is the amount of
2004 Oct 08
1
nlme vs gls
Dear List:
My question is more statistical than R oriented (although it originates
from my work with nlme). I know statistical questions are occasionally
posted, so I hope my question is relevant to the list as I cannot turn
up a solution anywhere else. I will frame it in the context of an R
related issue.
To illustrate the problem, consider student achievement test score data
with multiple
2008 Jul 05
5
help about random generation of a Normal distribution of several variables
Hello.
Somebody knows how can I generate a set of n random vectors of a
normal distribution of several variables?
For example, I want to generate n=100 random vectors of two dimensions
for a normal with mean c(0,1) and variance matrix:
matrix(c(2,1,1,3),2,2).
Thanks in advance,
Arnau.
2010 Oct 04
1
Help with apply
Suppose I have the following data:
tmp <- data.frame(var1 = sample(c(0:10), 3, replace = TRUE), var2 = sample(c(0:10), 3, replace = TRUE), var3 = sample(c(0:10), 3, replace = TRUE))
I can run the following double loop and yield what I want in the end (rr1) as:
library(statmod)
Q <- 2
b <- runif(3)
qq <- gauss.quad.prob(Q, dist = 'normal', mu = 0, sigma=1)
rr1 <- matrix(0,
2010 Mar 10
2
help R non-parametric IRT simulation
Hello R,
I am looking for non-parametric simulation in IRT. Is there any IRT
package that does non-parametric simulation?
helen L
[[alternative HTML version deleted]]