Displaying 20 results from an estimated 4000 matches similar to: "counting numbers without replicates in a vector"
2004 Jul 03
4
counting the occurrences of vectors
Hi:
I have two matrices, A and B, where A is n x k, and B is m x k, where n >> m >> k. Is there a computationally fast way to count the number of times each row (a k-vector) of B occurs in A? Thanks for any suggestions.
Best,
Ravi.
[[alternative HTML version deleted]]
2012 Aug 04
3
Head or Tails game
Hi,
Reading about a "Heads and Tails" game in
http://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/amsbook.mac.pdf
Introduction to Probability (Example 1.4, pp. 5-8).
You toss a coin 40 times. If heads, Peter wins $1, tails, he loses $1. I
think I can do that ok with:
winnings <- sum(sample(c(-1,1), 40, replace=TRUE))
But I have to do it 10,000 times
2010 Dec 15
3
Applying function to a TABLE and also "apply, tapply, sapply etc"
Dear R-help forum members,
Suppose I have a data-frame having two variables and single data for each of them, as described below.
variable_1 variable_2
10 20
I have written a function, say, 'fun' which uses input 10 and 20 and gives me desired result.
fun = function(X, Y)
{
X + Y #( I am just giving an example of
2010 Jun 29
1
Performance enhancement for ave
library(plyr)
n<-100000
grp1<-sample(1:750, n, replace=T)
grp2<-sample(1:750, n, replace=T)
d<-data.frame(x=rnorm(n), y=rnorm(n), grp1=grp1, grp2=grp2)
system.time({
d$avx1 <- ave(d$x, list(d$grp1, d$grp2))
d$avy1 <- ave(d$y, list(d$grp1, d$grp2))
})
# user system elapsed
# 39.300 0.279 40.809
system.time({
d$avx2 <- ave(d$x, interaction(d$grp1, d$grp2, drop =
2004 Jul 01
3
list structure question
Hi,
I have a list in which element is a vector (all of the same length and
all numeric). I want to find the mean of the first elements of the
vectors, the mean of the second elements of the vectors and so on.
Currently I convert the list to a data.frame and apply rowMeans(). But
is there a way to to do this directly on the list? I seem to recall a
post in which there was such a function (or
2008 Aug 27
5
Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Hey fellas:
I would like to integrate the following function:
integrand <- function (x,t) {
exp(-2*t)*(2*t)^x/(10*factorial(x))
}
with respect to the t variable, from 0 to 10.
The variable x here works as a parameter: I would like to integrate the said function for each value of x in 0,1,..,44.
I have tried Vectorize to no avail.
Thanks in advance,
jose romero
2007 Feb 08
2
Timings of function execution in R [was Re: R in Industry]
On 2/8/07, Albrecht, Dr. Stefan (AZ Private Equity Partner)
<stefan.albrecht at apep.com> wrote:
> Dear all,
>
> Thanks a lot for your comments.
>
> I very well agree with you that writing efficient code is about optimisation. The most important rules I know would be:
> - vectorization
> - pre-definition of vectors, etc.
> - use matrix instead of data.frame
> - do
2009 Dec 08
4
lower.tail option in pnorm
Hi,
I would have thought that these two constructions would
produce the same result but they do not.
Resp <- rbinom(10, 1, 0.5)
Stim <- rep(0:1, 5)
mm <- model.matrix(~ Stim)
Xb <- mm %*% c(0, 1)
ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb)))
pnorm(as.vector(Xb), lower.tail = Resp, log.p = TRUE)
> ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb)))
[1] -0.6931472 -1.8410216
2011 Sep 02
5
Hessian Matrix Issue
Dear All,
I am running a simulation to obtain coverage probability of Wald type
confidence intervals for my parameter d in a function of two parameters
(mu,d).
I am optimizing it using "optim" method "L-BFGS-B" to obtain MLE. As, I
want to invert the Hessian matrix to get Standard errors of the two
parameter estimates. However, my Hessian matrix at times becomes
2009 Nov 02
2
a prolem with constrOptim
Hi,
I apologize for the long message but the problem I encountered can't be stated in a few lines.
I am having some problems with the function constrOptim. My goal is to maximize the likelihood of product of K multinomials, each with four catagories under linear constraints on the parameter values. I have found that the function does not work for many data configurations.
#The likelihood
2008 Jun 03
3
How to solve a non-linear system of equations using R
Dear R-list members,
I've had a hard time trying to solve a non-linear system (nls) of equations
which structure for the equation i, i=1,...,4, is as follows:
f_i(d_1,d_2,d_3,d_4)-k_i(l,m,s) = 0 (1)
In the expression above, both f_i and k_i are known functions and l, m and s
are known constants. I would like to estimate the vector d=(d_1,d_2,d_3,d_4)
which is solution
2010 Jun 04
5
R Newbie, please help!
Hello Everyone,
I just started a new job & it requires heavy use of R to analyze datasets.
I have a data.table that looks like this. It is sorted by ID & Date, there
are about 150 different IDs & the dataset spans 3 million rows. The main
columns of concern are ID, date, and totret. What I need to do is to derive
daily returns for each ID from totret, which is simply totret at time
2017 Jul 16
2
About doing figures
Hi R users,
I still have the problem about plotting. I wanted to put the datasets on
one figure, x-axis represents values B, y-axis represents values C, while
different colors label column A. Each record uses a circle on the figure,
while hollow circles represent DF=1 and solid circles represent DF=2. I put
my code below, but the A labels do not correspond to the true record, so I
don't know
2017 Jul 16
2
About doing figures
Hi Jim,
For true color, I meant that the points in the figure do not correspond to
the values from the dataframe. Also, why to use rainbow(9) here? And the
legend is straight in the middle, is it possible to reformat it to the very
bottom? Thanks again.
On Sun, Jul 16, 2017 at 2:50 AM, Jim Lemon <drjimlemon at gmail.com> wrote:
> Hi lily,
> As I have no idea of what the "true
2017 Jul 16
0
About doing figures
Hi lily,
As I have no idea of what the "true record" is, I can only guess.
Maybe this will help:
# get some fairly distinct colors
rainbow_colors<-rainbow(9)
# this should sort the numbers in dfm$A
dfm$Acolor<-factor(dfm$A)
plot(dfm$B,dfm$C,pch=ifelse(dfm$DF==1,1,19),
col=rainbow_colors[as.numeric(dfm$Acolor)])
legend("bottom",legend=sort(unique(dfm$A)),
2009 Jun 17
1
Coerce rectangular matrix to symmetrical square matrix
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have a rectangular matrix of size 920 by 85. I'd like to coerce it into a
square matrix such that all row/col names are present in the new matrix and the
additional values are zero.
As an example:
A B C D
A 1 2 3 4
E 5 6 7 8
F 9 10 11 12
Would be coerced to:
A B C D E F
A 1 2 3 4 5 9
B 2 0 0 0 6 10
C 3 0 0
2017 Jul 16
0
About doing figures
For more than 10 records, how to reformat the colors? Also, how to show the
first legend only, but at the bottom, while the second legend in your code
is not necessary? In all, the same A values have the same color, but
different symbols in DF==1 and DF==2.
Thanks for your help.
On Sun, Jul 16, 2017 at 9:28 AM, lily li <chocold12 at gmail.com> wrote:
> Hi Jim,
>
> For true color,
2006 Jun 21
1
Extract information from the summary of 'lm'
Hi Everyone,
I just don't know how to extract the information I
want from the summary of a linear regression model
fitting.
For example, I fit the following simple linear
regression model:
results = lm(y_var ~ x_var)
summary(results) gives me:
Call:
lm(formula = y_var ~ x_var)
Residuals:
Min 1Q Median 3Q Max
-5.9859 -1.5849 0.4574 2.0163 4.6015
Coefficients:
2018 Mar 05
0
data analysis for partial two-by-two factorial design
Hi Bert and David,
Thank you so much for willingness to spend some time on my problem!!! I have some statistical knowledge (going to get a master in applied statisitics), but do not have a chance to purse a phD for statistics, so I am always be careful before starting to do analysis and hope to gather supportive information from real statisticians.
Sorry that I did not tell more info about
2018 Mar 05
5
data analysis for partial two-by-two factorial design
David:
I believe your response on SO is incorrect. This is a standard OFAT (one
factor at a time) design, so that assuming additivity (no interactions),
the effects of drugA and drugB can be determined via the model you rejected:
For example, if baseline control (no drugs) has a response of 0, drugA has
an effect of 1, drugB has an effect of 2, and the effects are additive,
with no noise we