Displaying 20 results from an estimated 600 matches similar to: "how to prevent duplications of data within a loop"
2009 Jan 22
0
detecting the source of memory consumption (example provided)
I have read in a file (call it myData). The actual file is about
3000x30,000 columns and object.size() says myData takes:
> 737910472/(1024^2)
[1] 703.7263
Unfortunately, my program ends up using 40GB as indicated by maxvmem
on Unix, which causes my department's cluster to stop working.
Perhaps, I have some copying going on that I cannot find. I have
created an example below that mimics
2004 Mar 08
2
getting the std errors in the lm function
Hello,
I have a simple question for you:
making:
mylm<-lm(y~x)
summary(mylm)
I get the following results:
******************************************************
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 16.54087 0.19952 82.91 <2e-16 ***
x[1:19] -2.32337 0.04251 -54.66 <2e-16 ***
******************************************************
2010 Sep 14
1
NA confusion (length question)
Hi folks,
I am running a very simple regression using
mylm <- lm(mass ~ tarsus, na.action=na.exclude)
I would like the use the residuals from this analysis for more
regression but I'm running into a snag when I try
cbind(mylm$residuals, mydata) # where my data is the original data set
The error tells me that it cannot use cbind because the length of
mylm$residuals is
2003 Oct 11
1
Subclassing lm
I'd trying to subclass the "lm" class to produce a "mylm" class whose
instances behave like lm objects (are accepted by methods like summary.lm)
but have additional data or slots of my own design.
For starters:
setClass("mylm", "lm")
produces the somewhat cryptic:
Warning message:
Old-style (``S3'') class "mylm" supplied as a
2011 Aug 10
2
round() a data frame containing 'character' variables?
Dear all
It is difficult to use round(..., digits=2) on a data frame since one
has to first take care to remove non-numeric variables such as
'character' or 'factor':
> head(round(iris, 2))
Error in Math.data.frame(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, :
non-numeric variable in data frame: Species
> head(round(iris[1:4], 2))
Sepal.Length Sepal.Width Petal.Length
2011 May 20
2
extraction of mean square value from ANOVA
Hello,
I am randomly generating values and then using an ANOVA table to find the
mean square value. I would like to form a loop that extracts the mean square
value from ANOVA in each iteration. Below is an example of what I am doing.
a<-rnorm(10)
b<-factor(c(1,1,2,2,3,3,4,4,5,5))
c<-factor(c(1,2,1,2,1,2,1,2,1,2))
mylm<-lm(a~b+c)
anova(mylm)
Since I would like to use a loop to
2009 May 14
1
automated polynomial regression
Dear all -
We perform some measurements with a machine that needs to be
recalibrated. The best calibration we get with polynomial regression.
The data might look like follows:
> true_y <- c(1:50)*.8
> # the real values
> m_y <- c((1:21)*1.1, 21.1, 22.2, 23.3 ,c(25:50)*.9)/0.3-5.2
> # the measured data
> x <- c(1:50)
> # and the x-axes
>
> # Now I do the following:
2006 Jan 16
4
Standardized beta-coefficients in regression
Hello list,
I am used to give a lot of attention to the standardized regression
coefficients, which in SPSS are listed automatically.
Is there alternative to running the last two lines in the following example to
get all the information?
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
summary( lm(ctl ~ trt) )
2009 Mar 31
1
using "substitute" inside a legend
Hello list,
I have a linear regression:
mylm = lm(y~x-1)
I've been reading old mail postings as well as the plotmath demo and I came
up with a way to print an equation resulting from a linear regression:
model = substitute(list("y"==slope%*%"x", R^2==rsq),
list(slope=round(mylm$coefficients[[1]],2),rsq=round(summary(mylm)$adj.r.squared,
2)))
I have four models and I
2007 Apr 06
2
lm() intercept at the end, rather than at the beginning
Hi,
I wonder if someone has already figured out a way of making
summary(mylm) # where mylm is an object of the class lm()
to print the "(Intercept)" at the last line, rather than the first
line of the output. I don't know about, say, biostatistics, but in
economics the intercept is usually the least interesting of the
parameters of a regression model. That's why, say, Stata
2008 Aug 23
3
graphs for pretest data
Is there an easy way to make graphs for the following data. I have
pretest and posttest scores for men and
women. I would like to form a 'titlted segment' plot for the data.
That is, make segments joining the scores,
with different types of segments for men and women.
Example data:
menpre <- c(43,42,26,39,60,60,46)
menpost <- c(40,41,36,42,54,58,43)
womenpre <-
2008 Jul 09
3
randomly select duplicated entries
Using this data as an example
dat <- read.table(textConnection("Id myvar
12 1
12 2
12 6
34 9
34 4
34 8
65 15
65 23"), header = TRUE)
closeAllConnections()
how can I create another data set that does not have duplicate entries
for 'Id', but the included values
are randomly selected from the available ones.
Thanks!
Juliet
2009 Mar 07
6
using a noisy variable in regression (not an R question)
Hi, This is not an R question, but I've seen opinions given on non R
topics, so I wanted
to give it a try. :)
How would one treat a variable that was measured once, but is known to
fluctuate a lot?
For example, I want to include a hormone in my regression as an
explanatory variable. However, this
hormone varies in its levels throughout a day. Nevertheless, its levels differ
substantially
2010 Jul 15
2
replace negative numbers by smallest positive value in matrix
Hi Group,
I have a matrix, and I would like to replace numbers less than 0 by
the smallest minimum number. Below is an
small matrix, and the loop I used. I would like to get suggestions on
the "R way" to do this.
Thanks,
Juliet
# example data set
mymat <- structure(c(-0.503183609420937, 0.179063475173256, 0.130473004669938,
-1.80825226960127, -0.794910626384209, 1.03857280868547,
2009 Mar 02
3
ways to put multiple graphs on single page (using ggplot2)
Hi, Here are three plots:
library(ggplot2)
data(diamonds)
randind <- sample(nrow(diamonds),1000,replace=FALSE)
dsmall <- diamonds[randind,]
qplot(carat, data=dsmall, geom="histogram",binwidth=1)
qplot(carat, data=dsmall, geom="histogram",binwidth=.1)
qplot(carat, data=dsmall, geom="histogram",binwidth=.01)
What are ways to put these three plots on a single
2012 Mar 21
2
glmnet: obtain predictions using predict and also by extracting coefficients
All,
For my understanding, I wanted to see if I can get glmnet predictions
using both the predict function and also by multiplying coefficients
by the variable matrix. This is not worked out. Could anyone suggest
where I am going wrong?
I understand that I may not have the mean/intercept correct, but the
scaling is also off, which suggests a bigger mistake.
Thanks for your help.
Juliet Hannah
2008 Sep 22
2
adding layers in ggplot2 (data and code included)
Here is some sample data:
mydata <- read.table(textConnection("Est Group Tri
0 0 4.639644
1 0 4.579189
2 0 4.590714
0 1 4.443696
1 1 4.588243
2 1 4.650505
0 2 4.296608
1 2 4.826036
2 2 4.765386"),header=TRUE);
closeAllConnections();
I can form two plots,
2005 Jun 16
1
regressing each column of a matrix on all other columns
DeaR list
I would like to predict the values of each column of a matrix A by
regressing it on all other columns of the same matrix A. I do this with
a for loop:
A <- B <- matrix(round(runif(10*3,1,10),0),10)
A
for (i in 1:length(A[1,])) B[,i] <- as.matrix(predict(lm( A[,i] ~
A[,-i] )))
B
It works fine, but I need it to be faster. I've looked at *apply but
just can't
2009 Apr 20
3
what is R best for; what should one learn in addition to R
Hi,
I've been working with R for a couple of years, and I've
been able to get most of the things done that I needed (sometimes in
a roundabout way). A few experienced statisticians told me that
R is best for interactive data analysis, but for large-scale
computations, one needs something else.
I understand that this all depends on what you are trying to
accomplish, and R offers many ways