Displaying 20 results from an estimated 50 matches for "fac2".
Did you mean:
fac
2008 Sep 09
1
How do I compute interactions with anova.mlm ?
...interactions with more than two factors.
I suspect, I have to create a new "grouping" factor and then test with this factor to get these interactions (as it is hinted in R News 2007/2),
but I don't really know how to use this approach.
Here is my current code:
Two Factors: fac1, fac2
mlmfit <- lm(mydata~1)
mlmfit0 <- update(mlmfit, ~0)
% test fac1, works, produces same output as SAS
anova(mlmfit, mlmfit0, M = ~ fac1 + fac2, X = ~ fac2, idata = idata, test = "Wilks")
% test fac1*fac2 interaction, also works, also the same output as SAS
anova(mlmfit, mlmfit0, X...
2010 Oct 13
1
interaction contrasts
hello list,
i'd very much appreciate help with setting up the
contrast for a 2-factorial crossed design.
here is a toy example:
library(multcomp)
dat<-data.frame(fac1=gl(4,8,labels=LETTERS[1:4]),
fac2=rep(c("I","II"),16),y=rnorm(32,1,1))
mod<-lm(y~fac1*fac2,data=dat)
## the contrasts i'm interressted in:
c1<-rbind("fac2-effect in A"=c(0,1,0,0,0,0,0,0),
"fac2-effect in B"=c(0,1,0,0,0,1,0,0),
"fac2-effect in C"=c(0,...
2002 Oct 17
1
manova with Error?
Let's say I have a within-subject experiment with 2 observables, obs1 and ob2 and 2 independent factors, fac1 and fac2.
I can do
summary( aov( obs1~fac1*fac2 + Error(Subject/(fac1*fac2)) ) )
summary( aov( obs2~fac1*fac2 + Error(Subject/(fac1*fac2)) ) )
to test the 2 observables separately.
> summary( fit<-manova( cbind(obs1,obs2)~fac1*fac2 + Error(Subject/(fac1*fac2)) ) )
gives results that seem sensible...
2009 Oct 06
1
ggplot2: mapping categorical variable to color aesthetic with faceting
Hello Again... I?m making a faceted plot of a response on two categorical
variables using ggplot2 and having troubles with the coloring. Here is a
sample that produces the desired plot:
compareCats <- function(data, res, fac1, fac2, colors) {
require(ggplot2)
p <- ggplot(data, aes(fac1, res)) + facet_grid(. ~ fac2)
jit <- position_jitter(width = 0.1)
p <- p + layer(geom = "jitter", position = jit, color = colors)
print(p)
}
test <- data.frame(res = rnorm(100), fac1 = as.factor(r...
2009 May 22
1
regrouping factor levels
...fac1<-fac
levels(fac1)[c("a","b","c")]<-"A"
levels(fac1)[c("d","e","f")]<-"B"
levels(fac1)[c("g","h","i","j")]<-"C"
levels(fac1)
print(fac1)
##second method
fac2<-fac?
levels(fac2)[c(1,2,3)]<-"A"
levels(fac2)[c(2,3,4)]<-"B" # not c(4,5,6)
levels(fac2)[c(3,4,5,6)]<-"C" # not c(7,8,9,10)
levels(fac2)
print(fac2)
#third method
fac3<-fac
levels(fac3)<-list("A"=c("a","b","c"...
2007 Oct 30
2
flexible processing
Hello,
unfortunately, I don't know a better subject. I would like to be very flexible
in how to process my data.
Assume the following dataset:
par1 <- seq(0,1,length.out = 100)
par2 <- seq(1,100)
fac1 <- factor(rep(c("group1", "group2"), each = 50))
fac2 <- factor(rep(c("group3", "group4", "group5", "group6"), each = 25))
df <- data.frame(par1, par2, fac1, fac2)
Now, I would like to calculate e.g. the "sum" for par1 grouping by "fac1" and
the "mean" and "sd" fo...
2011 Oct 03
1
function recode within sapply
Dear List,
I am using function recode, from package car, within sapply, as follows:
L3 <- LETTERS[1:3]
(d <- data.frame(cbind(x = 1, y = 1:10), fac1 = sample(L3, 10,
replace=TRUE), fac2 = sample(L3, 10, replace=TRUE), fac3 = sample(L3,
10, replace=TRUE)))
str(d)
d[, c("fac1", "fac2")] <- sapply(d[, c("fac1", "fac2")], recode,
"c('A', 'B') = 'XX'", as.factor.result = TRUE)
d[, "fac3"] <- reco...
2011 Jun 17
1
question about split
...-users
I seem to be stumped on something simple. I want to split a data frame
by factor levels given in one or more columns e.g. given
dat <- data.frame(x = runif(100),
fac1 = rep(c("a", "b", "c", "d"), each = 25),
fac2 = rep(c("A", "B"), 50))
I know I can split it by fac1, fac2 by:
split(dat, list(dat$fac1, dat$fac2))
which gives a list of length 8 - as desired.
My question is, given a vector of column name(s) to split by, how can I
supply
split with these? I was thinking something like:...
2010 Nov 27
1
d.f. in F test of nested glm models
...ple (while errors are not overdispersed)
otherwise generates a comparable analysis of deviance table to my analysis.
Any help would be much appreciated.
Jonathan
counts <- c(rpois(100,5),rpois(100,20))
sites <- rep(100,200)
fac1 <- factor(c(rep("A",100),rep("B",100)))
fac2 <- factor(c(rep("C",50),rep("D",100),rep("C",50)))
model1 <- glm(counts ~ fac1 * fac2,family=quasipoisson, offset=log(sites))
model2 <- glm(counts ~ fac1 + fac2,family=quasipoisson, offset=log(sites))
anova(model1,model2,test="F")
Analysis of Devianc...
2009 Oct 02
1
ggplot2: proper use of facet_grid inside a function
Hello Again R Folk:
I have found items about this in the archives, but I?m still not getting
it right. I want to use ggplot2 with facet_grid inside a function with
user specified variables, for instance:
p <- ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~
fac2)
Where data, fac1, fac2 and res are arguments to the function. I have
tried
p <- ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~
as.name(fac2))
and
p <- ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(?. ~
fac2?)
But all of these produce the same error:
E...
2010 Apr 21
5
Bugs? when dealing with contrasts
...tr.sum" "contr.poly"
> scores <- rep(seq(-2, 2), 3); scores
[1] -2 -1 0 1 2 -2 -1 0 1 2 -2 -1 0 1 2
> fac <- gl(3, 5); fac
[1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
Levels: 1 2 3
>
> # I get this:
> model.matrix(~ scores:fac)
(Intercept) scores:fac1 scores:fac2 scores:fac3
1 1 -2 0 0
2 1 -1 0 0
3 1 0 0 0
4 1 1 0 0
5 1 2 0 0
6 1 0...
2007 Oct 17
1
passing arguments to functions within functions
...ass arguments from the
function I am writing to the nested functions.
There must be a way, but I have not been able to figure it out.
An example is below.
Any advice would be greatly appreciated.
Thanks, Dan
# some example data
df=expand.grid(rep=1:4, fac1=c("a","b"), fac2=c("c","d"), fac3=c
("e","f"))
df$resp1=rnorm(length(df$fac1))
df
# define a funciton to compute mean, std error and n.
meanstderr <- function(x) c(Mean=mean(x,na.rm=TRUE),se=sqrt(var
(x,na.rm=TRUE)/length(na.omit(x))), n=length(na.omit(x)))
# what I...
2002 Dec 13
1
Problem with lattice bwplot
...les with bwplot (I use
a small example data set just to illustrate the problem):
> d <- data.frame(
x=c(34.4, 12.4, NA, 65.3, NA, 12.0, 45.0, 645.0, 644.0,323.0),
fac1=c('a','a','b','a','b','a','a','c','c','c'),
fac2=c('v2','v2','v1','v2','v2','v2','v1','v2','v1','v2')
)
# ok, although "x" has only NA values for fac1=='b'
> bwplot(fac2 ~ x | fac1,data=d)
# not ok, if I try to use different scales in the X axis...
2006 Feb 13
2
?bug? strange factors produced by chron
Hallo all
Please help me. I am lost and do not know what is the problem. I have
a factor called kvartaly.
> attributes(kvartaly)
$levels
[1] "1Q.04" "2Q.04" "3Q.04" "4Q.04" "1Q.05" "2Q.05" "3Q.05" "4Q.05"
$class
[1] "factor"
> mode(kvartaly)
[1] "numeric"
> str(kvartaly)
Factor w/ 8
2001 Aug 30
1
lattice
Hello. I know that lattice is still in beta beta but. . .
Nick Ellis wrote to S-news with an example of 'trellis' with several
lines in each panel.
df<-expand.grid(fac1=letters[1:2],x=seq(0,1,0.1),fac2=LETTERS[1:4])
df$y<-df$x*codes(df$fac1)+codes(df$fac2)*df$x^2+rnorm(nrow(df))/3
xyplot(y ~ x | fac2,
groups=fac1,
data=df,
panel=function(x,y,subscripts,groups){
panel.superpose(x,y,subscripts,groups)
for(g in as.character(unique(groups[subs...
2002 Jul 11
0
lattice and crosstabs with empty cells
Suppose you have a dataframe with two factors, but not all the factor
levels appear together. For instance:
stuff<- structure(list(fac1 = structure(c(2, 1, 2, 2), .Label = c("down",
"up"), class = "factor"), fac2 = structure(c(1, 2, 1, 2), .Label = c("left",
"right"), class = "factor"), x = c(1, 1, 2, 2), y = c(1, 2, 2,
1)), .Names = c("fac1", "fac2", "x", "y"), row.names = c("1",
"2", "3", "4"),...
2004 Mar 18
1
help with aov
Hi all,
Suppose the following data and the simple model
y<-1:12+rnorm(12)
fac1<-c(rep("A",4),rep("B",4),rep("C",4))
fac2<-rep(c("D","C"),6)
dat<-data.frame(y,fac1,fac2)
tmp<-aov(y~fac1+fac2,dat)
the command tmp$coeff gives the fllowing results :
(Intercept) fac1B fac1C fac2D
3.307888 2.898187 7.409010 -1.088588
But mean(y) gives 6.199327 and is different of In...
2008 Jan 15
1
covariate in a glm
Hello mailing list!
I would like to know, how I can introduce a covariate in a glm, I've two factors and a covariate.
Thank you very much!
_______________________________________________________________________________________________
Michelangelo La Spina
Equipo de Protección de cultivos - Control Biológico
Departamento de Biotecnología y Protección de Cultivos
Instituto Murciano de
2002 Jun 04
2
Scaling on a data.frame
Hey,
hopefully there is an easy way to solve my problem.
All that i think off is lengthy and clumsy.
Given a data.frame d with columns VALUE, FAC1, FAC2, FAC3.
Let FAC1 be something like experiment number,
so that there are exactly the same number of rows for each level of FAC1
in the data.frame.
Now i would like to scale all values according to the center of its
experiment.
So i can apply s <- by(d[1], FAC1, scale).
But i don't want to los...
2004 Sep 01
1
obtaining exact p-values in mixed effects model
...ing lme (linear mixed effects) from the nlme library,
it appears that there is rounding of the p-values to zero, if
the p-value is less than about 1.0e-16. Is there a way we can obtain
the exact p-values from lme without rounding?
used commands:
library(nlme)
g<-lme(value~factor(fac1)+factor(fac2)+factor(fac1):factor(fac2),data=mydataframe,random=~1|factor(fac3))
ag<-anova(g)
kind regards, R. Alberts