search for: groupvar

Displaying 16 results from an estimated 16 matches for "groupvar".

2008 Dec 11
2
call lattice function in a function passing "groups" argument
...uld do something like densityplot(~ x, d, groups = y) If however I wanted to call the function "densityplot" within a function and pass the "groups" argument as an argument of that function, how would I have to proceed? It is not as straightforward as f <- function(data, groupvar) { densityplot(~ x, data, groups = groupvar) } probably because the lattice function "densityplot.formula" preprocesses the "groups" argument with groups <- eval(substitute(groups), data, environment(formula)) It there a way how I could pass the "groups" argum...
2004 Oct 12
1
lm#contrasts#one level in factor: bug or feature
(R.1.9.1; win2000) Since it's about the tenth time I had to write an "if" around this to catch the error ... Let's look at the line myfit<-lm(res~groupvar,data=Data) Here res is of numeric type and groupvar is a factor. On first sight, it would be logical that if groupvar had only one (single) level we would get: Error in "contrasts<-"(`*tmp*`, value = "contr.treatment") : contrasts can be applied only to factors wi...
2004 Mar 19
2
using "unstack" inside my function: that old scope problem again
...roblem, but I can't understand the answers. Can one of you try to explain this to me? Here's my example. Given a regression model and a variable, I want to use unstack() on the vector of residuals and make some magic with the result. But unstack hates me. PCSE <- function (tmodel,groupVar) { myres1 <- resid(tmodel) resUnstacked <- unstack(myres1, form = myres1 ~ groupVar)); E <- as.matrix(resUnstacked) SIGMA <- (1/nrow(E))*(t(E) %*% E) OMEGA <- diag(x=1, nrow=nrow(E), ncol=nrow(E)) %x% SIGMA X <- model.matrix(tmodel) XPRIMEXINV <- solve(t(X) %*% X...
2012 Jan 01
1
How to pass in a list of variables as an argument to a function?
...arC=c("g", "h", "i"), varD=c("old", "new")), n=1000, fail=rbinom(2700,1000, 0.01)) # add in one more column myData$pass = myData$n-myData$fail # List of grouping vars. ?I would like to pass this object around and use it as arguments in functions myGroupVars = c("varA", "varB", "varC") # create a new column that is the combination of the grouping vars (used in plotting with lattice) # Question 1: ?Is there a way to replace "varA, varB, varC" in the function below with an object? myData = transform(myData, group...
2008 May 23
3
Percentages for categorical data by group
...entage of each group that choose each response. For example I want to know what percentage of group 1 (which may have a value of 34456) choose response 1 and so on. Here is some code I wrote that generates a data frame like the one I have. pop <- matrix(1:100000) groupIDs <- sample(pop,500) groupVar <- sample(groupIDs,23000,replace=TRUE) responseVar <- sample(1:5,23000,replace=TRUE) example.data <- data.frame(groupVar,responseVar) Is there a fast way to calculate these percentages beyond writing loops to manually count the responses for each of the groups? Thanks, EG [[alternati...
2002 Jul 03
2
lda from MASS function
Hi all, I am using the lda function from the MASS library to measure the discriminance of different variables with respect to different grouping variables by using lda( RESULTVARS[, 1:750] , GROUPVAR , tol=0 ) where RESULTVARS contains some 750 different variables. Occasionally there is a variable within RESULTVARS that has the same values for all values of GROUPVAR, ie no variance so I get the error: Error in svd(X, nu = 0) : NA/NaN/Inf in foreign function call (arg 1) As I understand it...
2011 Oct 23
0
code review: is it too much to ask?
...standard deviation, standard error of the mean, and confidence interval (default 95%). ## If there are within-subject variables, calculate adjusted values using method from Morey (2008). ## data: a data frame. ## measurevar: the name of a column that contains the variable to be summariezed ## groupvars: a vector containing names of columns that contain grouping variables ## na.rm: a boolean that indicates whether to ignore NA's ## conf.interval: the percent range of the confidence interval (default is 95%) summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE, conf....
2010 Feb 18
2
Extract p-value from aftreg object
...ct specific p-values for covariates from an aftreg object? After fitting a model with aftreg I can find all different variables by using str(), but there's no place where p-values are kept. The odd thing is that print() displays them correctly. EXAMPLE: > testdata start stop censor groupvar var1 var2 1 0 1 0 1 0.91663902 0.0847912 2 1 2 0 1 0.60470753 0.6487798 3 2 3 0 1 0.09599891 0.2195178 4 3 4 1 1 0.86384189 0.6667897 5 0 1 0 2 0.07747445 0.8782836 6 1 2 0 2...
2010 Feb 12
2
Access dataframe with variable name in function
...I want to write a function that returns a certain column of a dataframe. The function accepts two argument: the dataframe and the name of the column, but the column is not given as a "string" but as a variable name. EXAMPLE ---------------------- > testdata start stop censor groupvar var1 var2 1 0 1 0 1 0.91663902 0.0847912 2 1 2 0 1 0.60470753 0.6487798 3 2 3 0 1 0.09599891 0.2195178 x k <- function(df, col) df[col] EXPECTED RESULTS ------------------------------------- k(testdata, var1) should return the...
2010 Feb 19
1
eha aftreg performance
...tory). Generally it's not a problem for me as I can use the linux version, but maybe you have an idea what makes it so slow. If I can provide you with more details or help on fixing it, let me know. Here's the dump for reconstruction: > library(eha) > testdata start stop censor groupvar var1 var2 1 0 1 0 1 0.91663902 0.0847912 2 1 2 0 1 0.60470753 0.6487798 3 2 3 0 1 0.09599891 0.2195178 4 3 4 1 1 0.86384189 0.6667897 5 0 1 0 2 0.07747445 0.8782836 6 1 2 0 2...
2012 Mar 12
2
Replicating Stata's xtreg clustered SEs in R
I'm trying to replicate a time-series cross-sectional analysis (countries over years) with SEs clustered by country. ?The original analysis was done in Stata 10 with: xtreg [DV] [IVs] fe cluster(country). Using plm() in R (cran.r-project.org/web/packages/plm/index.html), I've replicated the coefficients. I sought to estimate country-clustered SEs with vcovHC(), and tried a variety of
2010 Feb 05
3
AFTREG with ID argument
Dear all, I have some trouble using the "id"-argument with aftreg (accelerated failure time regression analysis from the eha library). As far as I understand it, the id argument is used to group individuals together if there are time-varying covariates and the data is arranged in counting process style. Unfortunately, i cannot figure out how to use the "id"-argument. The
2011 May 05
4
Using functions/loops for repetitive commands
I still need to do some repetitive statistical analysis on some outcomes from a dataset. Take the following as an example; id sex hiv age famsize bmi resprate 1 M Pos 23 2 16 15 2 F Neg 24 5 18 14 3 F Pos 56 14 23 24 4 F Pos 67 3 33 31 5 M Neg 34 2 21 23 I want to know if there are statistically detectable differences in all of the continuous variables in
2008 Mar 26
2
ggplot2 argument handling odd
Hello there, I'm trying to do lots of plots in one for-loop. But somehow ggplot does not evaluate arguments as expected. Here is an example: library(lattice) library(ggplot2) pl <- list() pl2 <- list() cDat <- as.data.frame(cbind(x1=0:100,x2=0:10,x3=1:20)) for(obs in c("x1", "x2")) { pl[[obs]] <- xyplot(cDat[,obs] ~ cDat[,"x3"], main=obs)
2012 Apr 19
4
Column(row)wise minimum and maximum
Hi, Currently, the "base" has colSums, colMeans. It seems that it would be useful to extend this to also include colMin, colMax (of course, rowMin and rowMax, as well) in order to facilitate faster computations for large vectors (compared to using apply). Has this been considered before? Please forgive me if this has already been discussed before. Thanks, Ravi Ravi Varadhan, Ph.D.
2002 Apr 16
6
Classification Analysis
Hi everyone, Could somebody explain to me what is the package/function for classification analysis. I am performing analysis of music files in the form of MIDI files. I end up with about 750 dependent variables from the analysis, I also have a number of independent/grouping variables that I set manually. What I would like is to be able to predict which group a particular MIDI files belongs to