Displaying 20 results from an estimated 2000 matches similar to: "Arbitrary number of covariates in a formula"
2011 May 30
2
Group by multiple variables
Hello,
I would like to create a group variable that is based on the values of three variables:
For example,
> dat <- data.frame(A=c(1,1,1,1,1,2,2,2,2,2),
B=c(1,1,1,5,5,5,9,9,9,9),
C=c(1,1,1,1,1,2,2,7,7,7))
> dat
A B C
1 1 1 1
2 1 1 1
3 1 1 1
4 1 5 1
5 1 5 1
6 2 5 2
7 2 9 2
8 2 9 7
9 2 9 7
10 2 9 7
All rows that that are
2011 Sep 28
1
Multiplying a list of matrices with a vector
Hi all!
I have a list of matrices and I want to multiply the ith element of the list with the ith element of a another vector. That is,
> LL <- list(A=diag(3),B=diag(3),C=diag(3))
> vec <- 1:3
> for(i in 1:3)
+ {
+ LL[[i]] <- LL[[i]]*vec[i]
+ }
> LL
$A
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
$B
[,1] [,2] [,3]
[1,] 2 0
2006 Oct 19
5
write data to pdf
Hello!
Is there a possibility in R to save data in pdf-format?
I do not want to save a plot but some lines of simple text.
Regards,
Franco Mendolia
2006 Aug 02
2
tcl/tk bind destroy event
Hello!
I want to create a messagebox whenever the user wants to destroy the window
(e.g. <Alt-F4> or the 'x' in the right top corner) and ask if a modified file
should be saved or not.
If 'cancel' is chosen then nothing should happen and the windows still should be
existing. This doesn't work. When I press cancel the window will be destroyed
although.
I also
2011 Jun 28
1
parallel computing with 'foreach'
Hi all,
I would like to parallelize some R code and would like to use the 'foreach'
package with a foreach loop. However, whenever I call a function from an
enabled package outside of MASS, I get an error message that a number of the
functions aren't recognized (even though the functions should be defined).
For example:
library(foreach)
library(doSMP)
library(survival)
# Create the
2018 Mar 02
1
Variable centring within "predict.coxph"
Dear R-help,
I am using R-3.3.2 on Windows 10. I teach on a course which has 4 computer practical sessions related to the development and validation of clinical prediction models. These are currently written for Stata and I am in the process of writing them for use in R too (as I far prefer R to Stata!)
I notice that predictions made from a Cox model in Stata are based on un-centred variables,
2002 Jun 19
1
best selection of covariates (for each individual)
Dear All,
This is not strictly R related (though I would implement the solution in R;
besides, being this list so helpful for these kinds of stats questions...).
I got a "strange" request from a colleage. He has a bunch (approx. 25000)
subjects that belong to one of 12 possible classes. In addition, there are 8
covariates (factors) that can take as values either "absence"
2008 Feb 20
3
reshaping data frame
Dear all,
I'm having a few problems trying to reshape a data frame. I tried with
reshape{stats} and melt{reshape} but I was missing something. Any help is
very welcome. Please find details below:
#################################
# data in its original shape:
indiv <- rep(c("A","B"),c(10,10))
level.1 <- rpois(20, lambda=3)
covar.1 <- rlnorm(20, 3, 1)
level.2
2008 Dec 28
1
Random coefficients model with a covariate: coxme function
Dear R users:
I'm new to R and am trying to fit a mixed model
Cox regression model with coxme function.
I have one two-level factor (treat) and one
covariate (covar) and 32 different groups
(centers). I'd like to fit a random coefficients model, with treat and covar
as fixed factors and a random intercept, random
treat effect and random covar slope per center.
I haver a couple of
2010 May 24
2
Table to matrix
Dear R users,
I am trying to make this (3 by 10) matrix A
--A----------------------------------------------------
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0.5 0.5 0 0 0 0 0 0 0
-------------------------------------------------------
from "mass.func"
--mass.func-------------------------------------------
> mass.func
$`00`
prop
5
1
$`10`
2006 Feb 20
1
var-covar matrices comparison:
Hi,
Using package gclus in R, I have created some graphs that show the
trends within subgroups of data and correlations among 9 variables (v1-v9).
Being interested for more details on these data I have produced also the
var-covar matrices.
Question: From a pair of two subsets of data (with 9 variables each, I
have two var-covar matrices for each subgroup, that differ for a
treatment on one
2010 Aug 31
1
Q about package Icens: change the color of the shading in plot function
Hello!
I want to use the Icens package for analyzing interval-censored data. This code from the manual gives me what I want.
library(Icens)
data(cosmesis)
csub1 <- subset(cosmesis, subset=Trt==0, select=c(L,R))
e1 <- VEM(csub1)
plot(e1)
However, I would like to change the color of the shading from green to something less green, say gray. Any ideas how I could do that? I looked at par, but
2007 Apr 11
1
creating a path diagram in sem
Hello,
I finally run my measurement model in sem - successfully. Now, I am trying to print out the path diagram that is based on the results - but for some reason it's not working. Below is my script - but the problem is probably in my very last line:
# ANALYSIS OF ANXIETY, DEPRESSION, AND FEAR - LISREL P.31
library(sem)
# Creating the ANXIETY, DEPRESSION, AND FEAR intercorrelation matrix
2007 Apr 09
3
sem vs. LISREL: sem fails
I am new to R.
I just tried to recreate in R (using sem package and the identical input data) a solution for a simple measurment model I have found before in LISREL. LISREL had no problems and converged in just 3 iterations.
In sem, I got no solution, just the warning message:
"Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
in: sem.default(ram =
2013 Mar 11
2
How to 'extend' a data.frame based on given variable combinations ?
Dear expeRts,
I have a data.frame with certain covariate combinations ('group' and 'year')
and corresponding values:
set.seed(1)
x <- data.frame(group = c(rep("A", 4), rep("B", 3)),
year = c(2001, 2003, 2004, 2005,
2003, 2004, 2005),
value = rexp(7))
My goal is essentially to
2006 Feb 22
1
var-covar matrices comparison
> Date: Mon, 20 Feb 2006 16:43:55 -0600
> From: Aldi Kraja <aldi at wustl.edu>
>
> Hi,
> Using package gclus in R, I have created some graphs that show the
> trends within subgroups of data and correlations among 9 variables (v1-v9).
> Being interested for more details on these data I have produced also the
> var-covar matrices.
> Question: From a pair of two
2010 Jan 07
1
faster GLS code
Dear helpers,
I wrote a code which estimates a multi-equation model with generalized
least squares (GLS). I can use GLS because I know the covariance matrix of
the residuals a priori. However, it is a bit slow and I wonder if anybody
would be able to point out a way to make it faster (it is part of a bigger
code and needs to run several times).
Any suggestion would be greatly appreciated.
Carlo
2012 Jul 26
2
coxph weirdness
Hi all,
I cant' wrap my head around an error from the coxph function (package
survival). Here's an example:
library(survival)
n = 100;
set.seed(1);
time = rexp(n);
event = sample(c(0,1), n, replace = TRUE)
covar = data.frame(z = rnorm(n));
model = coxph(Surv(time, event)~ . , data = covar)
R gives the following error:
> model = coxph(Surv(time, event)~ . , data = covar)
Error in
2012 Oct 04
1
geoRglm with factor variable as covariable
Dear R users.
I'm trying to fit a generalised linear spatial mode using the geoRglm
package. To do so, I'm preparing my data (geodata) as follow:
geoData9093 = as.geodata(data9093, coords.col= 17:18, data.col=15,*
covar.col=16*)
where covar.col is a factor variable (years in this case 90-91-92-93)).
Then I run the model as follow:
/
model.5 = list(cov.pars=c(1,1),
2002 Feb 20
3
Pointer to covariates?
In the first line, use the dist function, found in library mva,
to get the distance between each pair of rows. From this
calculate an incidence matrix for which element i,j is true if
row i in dat equals row j in dat (and false elsewhere).
In the second line, for each row calculate the indices of
the matching rows and take the minimum of those as the key.
incid <-