Displaying 20 results from an estimated 40000 matches similar to: "apply lm() to each row of a matrix"
2011 Oct 11
2
replicate data.frame n times
Hi,
is there a way to replicate a data.frame like you can replicate the entries of a vector (with the repeat-function)?
I want to do this:
x <- data.frame(x, x)
(where x is a data.frame).
but n times.
And it should be as cpu / memory efficient as possible, since n is pretty big in my case.
thanks for any suggestions!
2012 Sep 25
1
mean-aggregate – but use unique for factor variables
Hi,
I have a data.frame which I want to aggregate.
There are some grouping variables and some continuous variables for which I would like to have the mean.
However there are also some factor-variables in the data-frame that are not grouping variables and I actually would like to aggregate these variables with the unique() function.
Is that possible with the standard aggregate-function?
If I
2010 Apr 15
2
predict.lm with NAs
Hi,
I wanted to use the predict.lm() function to compare the empirical data with the predicted values.
The problem is that I have NAs in my data.
I wanted to cbind my data.frame with the empirical values with the vector I get from predict.lm.
But they don't have the same length because predict.lm just skip NA-predictions.
Is there a way to get a vector with predicted values of the same
2008 Oct 05
3
efficient use of lm over a matrix vs. using apply over rows
I have a large matrix, each row of which needs lm applied. I am certain than
I read an article in R-news about this within the last year or two that
discussed the application of lm to matrices but I'll be darned if I can find
it with Google. Probably using the wrong search terms.
Can someone steer me to this article of just tell me if this is possible
and, if so, how to do it? My simplistic
2012 Apr 18
3
how to plot separate lm ablines on the same xyplot by group
Hi,
I am trying to use xyplot to plot the relationship between size and day
(y~x) by a food factor that has two levels, low and high. I have 3 reps per
factor/day. I want the plots from each food treatment on the same axiss,
so I used this code:
xyplot(Size ~ Day, groups = Food, data = louis.data.means,col=1,
pch=c(1,17),
panel=function(x,y,groups,...){
panel.superpose(x,y,groups,...)
2012 Dec 25
5
aggregate / collapse big data frame efficiently
Hi,
I need to aggregate rows of a data.frame by computing the mean for rows with the same factor-level on one factor-variable;
here is the sample code:
x <- data.frame(rep(letters,2), rnorm(52), rnorm(52), rnorm(52))
aggregate(x, list(x[,1]), mean)
Now my problem is, that the actual data-set is much bigger (120 rows and approximately 100.000 columns) ? and it takes very very long
2011 Dec 26
4
Other ways to lm() regression? (non-loop?)
Hi, I'm quite new to R (1 month full time use so far). I have to run loop
regressions VERY often in my work, so I would appreciate some new
methodology that I'm not considering.
#---------------------------------------------------------------------------------------------
y<-matrix(rnorm(100),ncol=10,nrow=10)
x<-matrix(rnorm(50),ncol=5,nrow=10)
#Suppose I want to run the
2013 Feb 14
4
lm regression query
Hello:
I have a 4-column dataset: Crime, Education, Urbanization, Age. I want to
construct a multiple linear regression to find the effect of Education,
Urbanization, and Age on Crime"
lm(Crime ~ Education + Urbanization + Age)
If I use + in above statement, does it mean it will build a model to find
the relationship between Crime and Education when Urbanization and Age are
held constant?
2012 Jan 09
1
Different lm() Residuals Output
All but one of the summaries of multiple linear regressions in this
analysis set present the residuals by min, 1Q, median, 3Q, and max. Example:
lm(formula = TDS ~ Cond + Ca + Cl + Mg + Na + SO4, data = snow.cast)
Residuals:
Min 1Q Median 3Q Max -277.351 -32.551 -2.621
40.812 245.272
The one that doesn't has only a small number of rows (23) and presents the
2013 Mar 06
2
lm and Formula tutorial
Dear all,
I was reading last night the lm and the Formula manual page, and 'I have to admit that I had tough time to understand their syntax. Is there a simpler guide for the dummies like me to start with?
I would like to thank you in advance for your help
Regards
Alex
[[alternative HTML version deleted]]
2011 Sep 30
1
different results aov vs. lm
Hi,
I currently running regression models on an experimental dataset.
The model contains one independent continuous variable and two independent experimental conditions (one with two factors, the other with three factors) and several covariates.
Now I get different results for a covariate in this model when I run
aov(modell) vs. lm(modell).
In the ancova model, one of the covariates seems to
2013 Jan 11
3
aggregate data.frame based on column class
Hi,
When using the aggregate function to aggregate a data.frame by one or more grouping variables I often have the problem, that I want the mean for some numeric variables but the unique value for factor variables.
So for example in this data-frame:
data <- data.frame(x = rnorm(10,1,2), group = c(rep(1,5), rep(2,5)), gender =c(rep('m',5), rep('f',5)))
aggregate(data,
2013 Feb 06
2
The interpretation of lm(y~x)?
Hi,
I am reading the book "Mixed Effects Models in S and S-Plus" and come
across an example with the Rail data.
I tried to use lm(travel~Rail,data=Rail) and got the following result:
Call:
lm(formula = travel ~ Rail, data = Rail)
Residuals:
Min 1Q Median 3Q Max
-6.6667 -1.0000 0.1667 1.0000 6.3333
Coefficients:
Estimate Std. Error t value Pr(>|t|)
2011 Aug 22
2
test if vector contains elements of another vector (disregarding the position)
Hi,
I have the following problem:
I have two vectors:
i <- c('a','c','g','h','b','d','f','k','l','e','i')
j <- c('a', 'b', 'c')
now I would like to generate a vector with the length of i that
has zeros where i[x] != any element of j
and 1 where i[x] == any element of j.
2011 Sep 09
3
split variable / create categories
Hi,
is there a function or an easy way to convert a variable with continuous values into a categorial variable (with x levels)?
here is what I mean:
I want to transform x:
x <- c(3.2, 1.5, 6.8, 6.9, 8.5, 9.6, 1.1, 0.6)
into a 'categorial'-variable with four levels so that I get:
[1] 2 2 3 3 4 4 1 1
so each element is converted into its rank- value / categorial-value
(in
2011 Nov 03
2
variable transformation for lm
Hello,
I am doing a simple regression using lm(Y~X).
As my response and my predictor seemed to be skewed
and I can't meet the model assumptions. Therefore
I need to transform my variables.
I wanted to ask what is the preferred way to find out
if predictor and/or response needs to be transformed
and if yes how (log-transform?).
I found a procedure in "A modern approach to Regressoin
in
2011 Dec 02
2
Unexplained behavior of level names when using ordered factors in lm?
Hello dear all,
I am unable to understand why when I run the following three lines:
set.seed(4254)
> a <- data.frame(y = rnorm(40), x=ordered(sample(1:5, 40, T)))
> summary(lm(y ~ x, a))
The output I get includes factor levels which are not relevant to what I am
actually using:
Call:
> lm(formula = y ~ x, data = a)
> Residuals:
> Min 1Q Median 3Q Max
>
2009 Nov 18
2
error message; ylim + log="y"
Hi,
I get a lot of error messages with this command, but I don't understand why;
plot(c(),c(), xlim=c(1,10), ylim=c(0,10000), log="y")
thanks for any help!
[[alternative HTML version deleted]]
2012 Aug 21
2
define subset argument for function lm as variable?
Hi
I want to do a series of linear models, and would like to define the input arguments for lm() as
variables. I managed easily to define the formula arguments in a variable, but I also would like to
have the "subset" in a variable. My reasoning is, that I have the subset in the results object.
So I wiould like to add a line like:
subs <- dead==FALSE & recTreat==FALSE
which
2011 Oct 05
2
mean of 3D arrays
Hi,
I have multiple three dimensional arrays.
Like this:
x1 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10))
x2 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10))
x3 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10))
Now I would like to compute the mean for each corresponding cell.
As a result I want to get one 3D array (10 x 10 x 10) in which at position x, y, z is the mean of the