Displaying 20 results from an estimated 900 matches similar to: "Which "apply" function to use?"
2009 Oct 01
1
Help me replace a for loop with an "apply" function
...if that is possible
My task is to find the longest streak of continuous days a user participated
in a game.
Instead of writing an sql function, I chose to use the R's rle function, to
get the longest streaks and then update my db table with the results.
The (attached) dataframe is something like this:
day user_id
2008/11/01 2001
2008/11/01 2002
2008/11/01 2003
2011 Sep 28
2
apply lm function to dataset split by two variables
Dear all,
I am not fluent in R and am struggling to 1) apply a lm to a weight-size
dataset, thus the model has to run separately for each species, each
year; 2) extract coefs, r-squared, n, etc. The data look like this:
year sps cm w
2009 50 16 22
2009 50 17 42
2009 50 18 45
2009 51 15 45
2009 51 16 53
2009 51 17 73
2010 50 15 22
2010 50 16 41
2010 50 16 21
2010
2008 Aug 28
2
Defining environments within functions
How can I define environments within a function so that they are visible
to calls to a sub-function?
I have defined an objective function,
ProfileErr = function(params,...)
which I would like to optimize using standard routines (optim,
nlminb,....) but which contains auxiliary variables which need to be
updated along with params. No optimization routine in R that I have
found has facilities
2003 Oct 27
3
assign a constant to a different column for each row
Hi all
I want to assign a constant to a different column for each row
eg:
m[1,2] <- 0;
m[2,3] <- 0;
m[3,1] <- 0;
m[4,2] <- 0;
m[5,1] <- 0;
...
etc...
i've tried apply/tapply with no luck
and also the following
coefs <- rtt.abs[,5:8];
coefs.i <- coefs[] == 1;
coefs[coefs.i] <- 0;
wich results in
"matrix subscripts not allowed in replacement"
2010 Sep 29
1
Understanding linear contrasts in Anova using R
#I am trying to understand how R fits models for contrasts in a
#simple one-way anova. This is an example, I am not stupid enough to want
#to simultaneously apply all of these contrasts to real data. With a few
#exceptions, the tests that I would compute by hand (or by other software)
#will give the same t or F statistics. It is the contrast estimates that
R produces
#that I can't seem to
2011 Jan 13
1
question about svm(e1071)
Dear all,
I executed svm calculation using e1071 library with a microarray data (http://www.iu.a.u-tokyo.ac.jp/~kadota/R/data_Singh_RMA_3274.txt).
Then, I shuffled the data samples and executed svm calculation again.
The results of 2 calculation were different (in SV, coefs and weights).
I attached the script below. Could please tell me why this happens?
If possible please tell me how to make
2009 Oct 23
2
interpretation of RCS 'coefs' and 'knots'
Hi,
I have fit a series of ols() models, by group, in this manner:
l <- ols(y ~ rcs(x, 4))
... where the series of 'x' values in each group is the same, however knots
are not always identical between groups. The result is a table of 'coefs'
derived from the ols objects, by group:
group Intercept top top' top''
1 6.864 0.01 2.241 -2.65
2007 Jan 25
1
poly(x) workaround when x has missing values
Often in practical situations a predictor has missing values, so that poly
crashes. For instance:
> x<-1:10
> y<- x - 3 * x^2 + rnorm(10)/3
> x[3]<-NA
> lm( y ~ poly(x,2) )
Error in poly(x, 2) : missing values are not allowed in 'poly'
>
> lm( y ~ poly(x,2) , subset=!is.na(x)) # This does not help?!?
Error in poly(x, 2) : missing values are not allowed in
2007 Jul 30
2
problems saving and loading (PLMset) objects
Hi
I'm running the latest R on a presumably up to date Linux server.
'Doing something silly I'm sure, but can't see why my saved PLMset objects
come out all wrong. To use an example:
Setting up an example PLMset (I have the same problem no matter what example
I use)
> library(affyPLM)
> data(Dilution) # affybatch object
> Dilution = updateObject(Dilution)
2007 Nov 23
4
help pleaseeeeeeeee
Dears Sirs
During my computational work I encountered unexpected behavior when calling
"ar" function, namely
# time series
x<-ts(c(-0.2052083,-0.3764986,-0.3762448,0.3740089,0.2737568,2.8235722,-
1.7783313,0.2728676,-0.3273164),start=c(1978,3),frequency=4,end=c(1980,3))
# ar function
res.ar<-ar(x,aic=TRUE,demean=F)
# call "ar" again and ............
2004 Nov 16
1
gcrma package
Hi !
I would like to understand where do affinity.spline.coefs used in function
compute.affinities come from ?
library(gcrma)
data(affinity.spline.coefs)
affinity.spline.coefs
X1 X2 X3 X4 X5 X1
-0.55004171 -0.58579091 -0.08870557 -0.47774242 0.23205570 0.58002746
X2 X3 X4 X5 X1 X2
2009 Mar 01
2
Formatted text output
How does one write formatted, say "C style", output to a text file. I want something like "y=mx+b" for my linear regressions but with m and b derived from the fit objects. Also, how does one go about extracting just the slope or intercept from such an object. - Greg
[[alternative HTML version deleted]]
2004 Apr 05
1
normalized regression output
Hi: I would like to write a function that takes as its input a formula
and outputs normalized coefficients ( coef(x)*sdv(x)/sdv(y) ). now, a
formula is an object, and I cannot see how to extract the variables for
obtaining sdv's. the intent is to write something like
my.print.lm( formula ) {
model <- lm(formula);
coefs <- (t(summary.lm(model)))[1,];
tvals <-
2010 Oct 13
1
(no subject)
Dear all,
I have just sent an email with my problem, but I think no one can see the red part, beacuse it is black. So, i am writing again the codes:
rm(list=ls()) #remove almost everything in the memory
set.seed(180185)
nsim <- 10
mresultx <- matrix(-99, nrow=1000, ncol=nsim)
mresultb <- matrix(-99, nrow=1000, ncol=nsim)
N <- 200
I <- 5
taus <- c(0.480:0.520)
h <-
2012 Jan 26
2
R extracting regression coefficients from multiple regressions using lapply command
Hi, I have a question about running multiple in regressions in R and then
storing the coefficients. I have a large dataset with several variables,
one of which is a state variable, coded 1-50 for each state. I'd like to
run a regression of 28 select variables on the remaining 27 variables of
the dataset (there are 55 variables total), and specific for each state, ie
run a regression of
2017 Apr 19
3
[PATCH] cosmetics,silk: correct input/output arg comments
Hi,
Attached is a patch for cosmetics purpose. Please review.
Thanks,
Linfeng Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xiph.org/pipermail/opus/attachments/20170419/34354707/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-cosmetics-silk-correct-input-output-arg-comments.patch
2012 Mar 20
2
Constraint Linear regression
Hi there,
I am trying to use linear regression to solve the following equation -
y <- c(0.2525, 0.3448, 0.2358, 0.3696, 0.2708, 0.1667, 0.2941, 0.2333,
0.1500, 0.3077, 0.3462, 0.1667, 0.2500, 0.3214, 0.1364)
x2 <- c(0.368, 0.537, 0.379, 0.472, 0.401, 0.361, 0.644, 0.444, 0.440,
0.676, 0.679, 0.622, 0.450, 0.379, 0.620)
x1 <- 1-x2
# equation
lmFit <- lm(y ~ x1 + x2)
lmFit
Call:
2012 Mar 31
2
lm no calcula un coeficiente
Hola,
quiero hacer una regresión lineal
lm(y ~ x * grupo, data =datos)
y: numérica, x: numérica, grupo: factor con dos niveles (1 y 2)
pero no calcula el coeficiente de x:grupo2 a cuenta de una singularidad
Coefficients: (1 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.283e+06 2.276e+04 -56.359 < 2e-16 ***
x
2009 Jun 05
1
Bug in print.Arima and patch
Dear List,
A posting to R-Help exposed this problem with the print method for
objects of class Arima:
> set.seed(1)
> x <- arima.sim(n = 100, list(ar = 0.8897, ma = -0.2279))
> mod <- arima(x, order = c(1,0,1))
> coefs <- coef(mod)
> mod2 <- arima(x, order = c(1,0,1), fixed = coefs)
> mod2
Call:
arima(x = x, order = c(1, 0, 1), fixed = coefs)
Coefficients:
Error
2003 Oct 09
3
simulate binary data from a logistic regression model
Hi.
How can i simulate a binary data set from a logistic
regression model?I need to manipulate parameters and so
obtain my set of data.
I want to show the improve in analyzing binary data
with GLM(binomial) model instead of classical ANOVA or
NON-MODELS procedures(relative risk-odds ratio-Pearson
test of godness of fit...)
Can you say me what is the right function to use?
Do you know any