Displaying 20 results from an estimated 20000 matches similar to: "Efficient method: Equality of all elements of two vectors"
2006 Jul 18
3
Test for equality of coefficients in multivariate multiple regression
Hello,
suppose I have a multivariate multiple regression model such as the
following:
> DF<-data.frame(x1=rep(c(0,1),each=50),x2=rep(c(0,1),50))
> tmp<-rnorm(100)
> DF$y1<-tmp+DF$x1*.5+DF$x2*.3+rnorm(100,0,.5)
> DF$y2<-tmp+DF$x1*.5+DF$x2*.7+rnorm(100,0,.5)
> x.mlm<-lm(cbind(y1,y2)~x1+x2,data=DF)
> coef(x.mlm)
y1 y2
(Intercept)
2011 Aug 02
1
My R code is not efficient
Dear R users,
I have two n*1 integer vectors, y1 and y2, where n is very very large.
I'd like to compute
elbp = 4^(y1) * 5^(y2) * sum_{i=0}^{max(y1, y2)} [{ (y1-i)! * (i)! *
(y2-i)! }^(-1)];
that is, I need to compute "elbp" for each (y1, y2) pair.
So I made R code like below, but I don't think it's efficient
Would you plz tell me how to avoid this "for"
2006 Jul 19
1
Test for equality of coefficients in multivariate multipleregression
Dear Berwin,
Simply stacking the problems and treating the resulting observations as
independent will give you the correct coefficients, but incorrect
coefficient variances and artificially zero covariances.
The approach that I suggested originally -- testing a linear hypothesis
using the coefficient estimates and covariances from the multivariate linear
model -- seems simple enough. For
2008 Jan 24
2
plot help
Hi,
Suppose I already have two plots on the same screen, and I want to draw
lines in each of them. Is that possible in R? It seems that once you have
two plots on the screen, you can only draw lines in the the last plot, never
the 1st. Here is what I mean:
#some data
y1=rnorm(1:3)
y2=rnorm(1:3)
#draw two plots on the same screen
par(mfrow=c(2,1),oma = c(6, 0, 5, 0))
par(mar=c(0, 5.1, 0, 5.1))
2007 Feb 23
4
How to plot two graphs on one single plot?
Hi,
I am trying to plot two distribution graph on one plot. But I dont know
how. I set them to the same x, y limit, even same x, y labels.
Code:
x1=rnorm(25, mean=0, sd=1)
y1=dnorm(x1, mean=0, sd=1)
x2=rnorm(25, mean=0, sd=1)
y2=dnorm(x2, mean=0, sd=1)
plot(x1, y1, type='p', xlim=range(x1,x2), ylim=range(y1, y2), xlab='x',
ylab='y')
plot(x2, y2, type='p',
2003 Jun 05
2
Fwd: Re: legend() with option adj=1
Is there a simpler way then the solution to the one that was posted here? I'm
not very proficient with legend, and I don't understand this solution. All
I have is two or more lines on one plot that I want to put a legend on and I
can't figure out how to do it from the examples. Can you give a very simple
example? It does not have to be fancy!! I have never worked with a
2009 Apr 07
1
use the value of variable to quote certain elements in matrix
Hi, I want to use the value of variable to quote elements in matrix.
For example, I have a matrix like:
y1 y2m1 1 2m2 3 4
where y1,y2,m1,m2 are column and row names. I have two random character variable, say x, that could be either y1 or y2 and y that could be either m1 or m2. So can I do like Matrix[y,x] to quote elements? I've tried this
2012 Mar 10
1
applying a function in list of indexed elements of a vector:
Hi,
I have a vector
Y1 <-c(8, 11, 7, 5, 6, 3, 6, 3, 3)
and an index
iy <-c(c(1, 2),c(1 2), c(1, 2, 3, 4), c(2, 3, 5), c(4), c(5, 6, 7), c(7,
8, 9))
how can I produce the mean, or the sum of the elements specified in the
index iy from the vector Y1?
expecting something like this for the sum:
Y2
19 19 31 24 5 15 12
I thought lapply function may perform this, but does not work:
2011 Jan 04
1
XTS : merge.xts seems to have problem with character vectors
Hi,
Please can you tell me what I am doing wrong. When trying to merge two xts
objects, one of which has multiple character vectors for columns...I am just
getting NAs.
> str(t)
POSIXct[1:1], format: "2011-01-04 11:45:37"
> y2 = xts(matrix(c(letters[1:10]),5), order.by=as.POSIXct(c(t + 1:5)))
> names(y2) = c(1,2)
> y2
1 2
2011-01-04 11:45:38
2011 Apr 24
2
Multi-dimensional non-linear fitting - advice on best method?
Hello!
I have a set of data of the form (x, y1, y2) where x is the
independent variable and (y1, y2) is the response pair. The model is
some messy non-linear function:
(y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2error)
where the parameters param1, ..., paramk are to be estimated, and I'll
assume the errors to be normal for sake of simplicity.
If there were only one
2008 Jan 29
3
How to get two y-axises in a bar plot?
Hi,
I have measured two response variables (y1, y2) at each treatment level
(x = 0, 1.5 or 3). Now I would like to show the y1 and y2 against x in a
bar plot. However, y1 and y2 differ in scale so I need two y-axises, one
on the left side and one on the right side (and I dont want to
standardize my responses). This is fairly easy if you want to show
points,lines etc, but gets more complicated
2013 Mar 17
3
help with simple function
hello all
I am writing a quite simple script to study dental wear patterns in humans
and I wrote this function
sqrt(var(Y1)+var(Y2))^2-4(var(Y1)*(var(Y2)-cov(Y1,Y2)^2)) but appear this
error message
Error: attempt to apply non-function
alternatively I wrote this
sqrt(var(Y1)+var(Y2)^2)-4[(var(Y1)*(var(Y2)-cov(Y1,Y2)^2))]
but this error message appear
[1] NA
Warning message:
NAs introduced
2012 May 14
3
How to apply a function to a multidimensional array based on its indices
Hello. I have a 4 dimensional array and I want to fill in the slots with
values which are a function of the inputs. Through searching the forums here
I found that the function "outer" is helpful for 2x2 matrices but cannot be
applied to general multidimensional arrays. Is there anything which can
achieve, more efficiently than the following code, the job I want?
K <-
2011 Aug 15
1
update() ignores object
Hi all,
I'm extracting the name of the term in a regression model that
dropterm specifies as the least significant one, and I'm assigning
this name to an object. However, when I use update(), it ignores this
object. Is there a way I can make it not ignore it? A reproducible
example is below:
> lm(x1~1+y1*y2+y3+y4,data=anscombe)->my.lm
>
2007 Jan 30
2
Rbind for appending zoo objects
Hi R,
y1 <- zoo(matrix(1:10, ncol = 2), 1:5)
colnames(y1)=c("a","b")
y2 <- zoo(matrix(rnorm(10), ncol = 2), 6:10)
colnames(y2)=c("b","a")
> y1
a b
1 1 6
2 2 7
3 3 8
4 4 9
5 5 10
> y2
b a
6 0.9070204 0.3527630
7 1.2405943 0.8275001
8 -0.1690653 -0.1724976
9 -0.6905223 -1.1127670
10
2010 Oct 17
1
lattice xyplot - formatting of multiple Y variables when using subgroups
Hi all,
Using xyplot I want to print to Y variables (y1, y2) versus X, conditional
on the group.
How can I obtain a line (type="l") for one relationship (ie. y1 ~ x) and
points (type="p") for the other (y2 ~ x) ?
library(lattice)
# create some sample data
df<-data.frame(group=as.factor(c(rep("a",4), rep("b",4))), # grouping
variable for conditional
2006 Mar 10
1
add trend line to each group of data in: xyplot(y1+y2 ~ x | grp...
Although this should be trivial, I'm having a spot of trouble.
I want to make a lattice plot of the format y1+y2 ~ x | grp but then fit a
lm to each y variable and add an abline of those models in different colors.
If the xyplot followed y~x|grp I would write a panel function as below, but
I'm unsure of how to do that with y1 and y2 without reshaping the data
before hand. Thoughts
2010 May 25
1
Assigning NA to a rows of a dataframe/datamatrix
Dear R-users, I have a problem, I have the following dataframe:
d<-data.frame(
'y1'=c(1,2,1,2,1,NA,NA),
'y2'=c(1,2,1,1,1,2,1),
'y3'=c(1,NA,1,NA,NA,2,1),
'y4'=c(NA,2,NA,1,1,2,NA),
'a'=c(1,1,1,1,1,1,2)
)
where the last variable counts the number of missing values in a row. Now, i want to set rows where a>1 to NA and arrive at something like the
2007 Oct 17
3
how to repeat the results of a generated probabilities
hello,
I want to simulate 200 times the mean of a joint probability (y1) and 200
times the mean of another joint distribution (y2),
that is I'm expecting to get 200 means of y1 and 200 means of y2.
y1 and y2 are probabilities that I calculate from the marginal prob. (z1 and
z2 respectively) multiple by the conditional prob. (x1 and x2 respectively),
which I generaterd from the binomial
2010 Feb 11
2
Find each time a value changes
Dear List,
I am trying to find each time a value changes in a dataset. The numbers are variables for day vs. night values, so what I am really getting is the daily sunrise and sunset.
A simplified example is the following:
x<-seq(1:100)
y1<-rep(1,10)
y2<-rep(2,10)
y<-c(y1,y2,y1,y1,y1,y2,y1,y2,y1,y2)
xy<-cbind(x,y)
I would like to know each time the numbers change.
Correct