Displaying 20 results from an estimated 40000 matches similar to: "What does model.matrix() return?"
2009 Sep 15
1
coefficients of aov results has less number of elements?
Hi,
I run the following commands. 'A' has 3 levels and 'B' has 4 levels.
Should there be totally 3+4 = 7 coefficients (A1, A2, A3, B1, B2, B3,
B4)?
> a=3
> b=4
> n=1000
> A = rep(sapply(1:a,function(x){rep(x,n)}),b)
> B = as.vector(sapply(sapply(1:b, function(x){rep(x,n)}), function(x){rep(x,a)}))
> Y = A + B + rnorm(a*b*n)
>
> fr =
2010 Feb 09
2
Model matrix using dummy regressors or deviation regressors
The model matrix for the code at the end the email is shown below.
Since the model matrix doesn't have -1, I think that it is made of
dummy regressors rather than deviation regressors. I'm wondering how
to make a model matrix using deviation regressors. Could somebody let
me know?
> model.matrix(aaov)
(Intercept) A2 B2 B3 A2:B2 A2:B3
1 1 0 0 0 0 0
2
2007 May 17
1
model.matrix bug? Nested factor yields singular design matrix.
Hi all,
I believe this is a bug in the model.matrix function.
I'd like a second opinion before filing a bug report.
If I have a nested covariate B with multiple values for
just one level of A, I can not get a non-singular design
matrix out of model.matrix
> df <- data.frame(A = factor(c("a", "a", "x", "x"), levels = c("x",
2010 Apr 21
5
Bugs? when dealing with contrasts
R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with
2006 Dec 14
2
Asymmetrical ANOVA / contrasts
Dear all,
I have problems to code contrasts for performing an asymmetrical anova
with aov(). I am using aov() because I want to get the Mean Squares for
further analyses. I didn't find any solution to my problem in the help
files of functions aov(), contrasts(), C(), etc.
Let's say I have three locations, one with treatment P, and two with
treatment C:
>
2001 Feb 08
2
Test for multiple contrasts?
Hello,
I've fitted a parametric survival model by
> survreg(Surv(Week, Cens) ~ C(Treatment, srmod.contr),
> data = poll.surv.wo3)
where srmod.contr is the following matrix of contrasts:
prep auto poll self home
[1,] 1 1 1.0000000 0.0 0
[2,] -1 0 0.0000000 0.0 0
[3,] 0 -1 0.0000000 0.0 0
[4,] 0 0 -0.3333333 1.0 0
[5,] 0 0
2004 Jun 24
3
problem with model.matrix
This works:
> model.matrix(~I(pos>3),data=data.frame(pos=c(1:5)))
(Intercept) I(pos > 3)TRUE
1 1 0
2 1 0
3 1 0
4 1 1
5 1 1
attr(,"assign")
[1] 0 1
attr(,"contrasts")
attr(,"contrasts")$"I(pos > 3)"
[1] "contr.treatment"
2007 Jun 28
2
aov and lme differ with interaction in oats example of MASS?
Dear R-Community!
The example "oats" in MASS (2nd edition, 10.3, p.309) is calculated for aov and lme without interaction term and the results are the same.
But I have problems to reproduce the example aov with interaction in MASS (10.2, p.301) with lme. Here the script:
library(MASS)
library(nlme)
options(contrasts = c("contr.treatment", "contr.poly"))
# aov: Y ~
2002 Dec 01
1
generating contrast names
Dear R-devel list members,
I'd like to suggest a more flexible procedure for generating contrast
names. I apologise for a relatively long message -- I want my proposal to
be clear.
I've never liked the current approach. For example, the names generated by
contr.treatment paste factor to level names with no separation between the
two; contr.sum simply numbers contrasts (I recall an
2008 Sep 26
1
Type I and Type III SS in anova
Hi all,
I have been trying to calculate Type III SS in R for an unbalanced two-way
anova. However, the Type III SS are lower for the first factor compared to
type I but higher for the second factor (see below). I have the impression
that Type III are always lower than Type I - is that right?
And a clarification about how to fit Type III SS. Fitting model<-aov(y~a*b)
in the base package and
2005 Feb 23
1
model.matrix for a factor effect with no intercept
I was surprised by this (in R 2.0.1):
> a <- ordered(-1:1)
> a
[1] -1 0 1
Levels: -1 < 0 < 1
> model.matrix(~ a)
(Intercept) a.L a.Q
1 1 -7.071068e-01 0.4082483
2 1 -9.073800e-17 -0.8164966
3 1 7.071068e-01 0.4082483
attr(,"assign")
[1] 0 1 1
attr(,"contrasts")
attr(,"contrasts")$a
[1]
2005 Jun 23
4
contrats hardcoded in aov()?
On 6/23/05, RenE J.V. Bertin <rjvbertin at gmail.com> wrote:
> Hello,
>
> I was just having a look at the aov function source code, and see that when the model used does not have an Error term, Helmert contrasts are imposed:
>
> if (is.null(indError)) {
> ...
> }
> else {
> opcons <- options("contrasts")
>
2017 Oct 12
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
Hi,
I recently ran into an inconsistency in the way model.matrix.default
handles factor encoding for higher level interactions with categorical
variables when the full hierarchy of effects is not present. Depending on
which lower level interactions are specified, the factor encoding changes
for a higher level interaction. Consider the following minimal reproducible
example:
--------------
>
2009 Nov 05
4
The equivalence of t.test and the hypothesis testing of one way ANOVA
I read somewhere that t.test is equivalent to a hypothesis testing for
one way ANOVA. But I'm wondering how they are equivalent. In the
following code, the p-value by t.test() is not the same from the value
in the last command. Could somebody let me know where I am wrong?
> set.seed(0)
> N1=10
> N2=10
> x=rnorm(N1)
> y=rnorm(N2)
> t.test(x,y)
Welch Two Sample t-test
data:
2006 Sep 23
1
contrasts in aov
useRs,
A no doubt simple question, but I am baffled. Indeed, I think I
once knew the answer, but can't recover it. The default contrasts
for aov (and lm, and...) are contr.treatment and contr.poly for
unordered and ordered factors, respectively. But, how does one
invoke the latter? That is, in a data.frame, how does one indicate
that a factor is an *ordered* factor such that
2011 May 11
1
Help with contrasts
Hi,
I need to build a function to generate one column for each level of a factor
in the model matrix created on an arbitrary formula (instead of using the
available contrasts options such as contr.treatment, contr.SAS, etc).
My approach to this was first to use the built-in function for
contr.treatment but changing the default value of the contrasts argument to
FALSE (I named this function
2005 Apr 13
2
multinom and contrasts
Hi,
I found that using different contrasts (e.g.
contr.helmert vs. contr.treatment) will generate
different fitted probabilities from multinomial
logistic regression using multinom(); while the fitted
probabilities from binary logistic regression seem to
be the same. Why is that? and for multinomial logisitc
regression, what contrast should be used? I guess it's
helmert?
here is an example
2012 Oct 27
1
contr.sum() and contrast names
Hi!
I would like to suggest to make it possible, in one way or another, to
get meaningful contrast names when using contr.sum(). Currently, when
using contr.treatment(), one gets factor levels as contrast names; but
when using contr.sum(), contrasts are merely numbered, which is not
practical and can lead to mistakes (see code at the end of this
message).
This issue was discussed quickly in 2005
2007 May 17
1
Design matrix question
Hi useRs,
Perhaps I am having a senior moment?
I have a nested variable situation to model,
toy example:
> df <- data.frame(A = factor(c("a", "a", "x", "x"), levels = c("x", "a")),
+ B = factor(c("b", "x", "x", "x"), levels = c("x", "b")))
>
>
2005 Jun 30
2
Finding out collinearity in regression
Hi, I am trying to find out a collinearity in
explanatory variables with alias().
I creat a dataframe:
dat <- ds[,sapply(ds,nlevels)>=2]
dat$Y <- Response
Explanatory variables are factor and response is
continuous random variable. When I run a regression, I
have the following error:
fit <- aov( Y ~ . , data = dat)
Error in "contrasts<-"(`*tmp*`, value =