[R] ... Error in names-.default(`*tmp*`, value = nmstrata)

2004-03-13 Thread Wolfgang Pauli
Hi,
OK, I will describe it in more detail.In the meantime I installed the newest debian 
package of r-base etc. and the error message changed from:Error in 
names-.default(`*tmp*`, value = nmstrata) : names attribute must be the 
same length as the vectorto:Error model is singular in: aov(rati ~ cs * spk + 
Error(sub/(cs * spk)), data = rating.df) 
The model is a repeated measures anova that's why I use the Error() term. I found the 
hint for this usage in Notes on the use of R for psychology experiments and 
questionaires (Jonathan Baron, 2003).cs and speaker are within-subjects factors. rati 
is the dependent variable: ratings done by subjects. sub are the subject-codes 
(between-subjects factor). SpaeVP is sorted because in the preprocessing I needed to 
recoded data of each subject and did:
testfac - as.factor(spaeVP)levels(testfac) - vpnso I could do for ( i in 
vpn).after that data (rati) was sorted so I sorted spaeVp too, before putting it 
into the dataframe. (I found no better solution (newbie))
Now follows the syntax I already sent last time. After that is more data of my 
dataframe. 
with best regards,
Wolfgang Pauli
I use:spk =factor(rep(c(spk1,spk2,spk3,spk4,spk5,spk6,spk7,spk8), 
c(2,2,2,2,2,2,2,2)))cs = factor(rep(c(yes,no),c(8,8)))sub = 
factor(sort(spaeVP))rati = stack(data.frame(arousal))rati = rati[,1]rating.df - 
 data.frame(sub, cs, spk, rati)summary(aov(rati ~ cs*spk + Error(sub/(cs*spk)), 
data=rating.df))
 arousal (30 subjects, and 16 stimuli) before using stack() and putting it into 
 rati      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] 
 [,13] [1,]   -1   -2   -1   -1   -2    0   -1    0   -2    -1     0     0    -2 [2,] 
    0    0    0    0   -1    1    0   -1   -2     0     1    -1    -1 [3,]    1   -1 
   -1   -2   -1    0    0    0   -3     0    -1     0     2 [4,]    0    0    2    0 
   -1    1    0    1    0     2    -2     1    -2 [5,]    0    0   -1   -1   -1    0 
    0    0    0     0     1     0     1 [6,]   -1    0   -2    0   -2    0    0    0 
    0     0    -1     1     0 [7,]   -1    0    0    0   -1    0    0   -1    0     1 
    -1     1    -1 [8,]    1    0    0    0   -1    0    0    1    0    -1    -3     
 0     1 [9,]    0   -1    0    0   -1    0    0    1    0    -1     0     1     
 3[10,]    0   -2   -1   -1    0    2    0   -2   -2     1    -1     2     1[11,]   
  0   -1    0    0    0   -1   -1    0   -1    -1     1     1     0[12,]   -1   -3   
  0   -2    0    0    0    0   -1     0     1     2     1[13,]    0   -1   -1   -1   
  0   -1    0   -1   -1    -1    -1     1     0[14,]    1    2    2   -1    0    0   
  0    0    1    -1     0     1     1[15,]    0    0    0   -1    0    1   -1   -1   
 -1     0    -1    -2     1[16,]    1    0   -2   -1    0   -1    0    0   -1     1   
   1     1     0      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] 
 [,24] [,25] [1,]     0     0     0     0     0     0     1     1     0     0     1   
   1 [2,]    -2     0    -1    -1     1    -3     3     0     0    -1     0     
 0 [3,]     1     0     0     0     1    -2     0    -1    -1     0     0    -1 [4,] 
     2     0     1     0     0     0     3    -1     1     0    -1     0 [5,]    -2   
   1    -1     1     0    -2     1     0     0     0    -1    -1 [6,]     0     1   
  -1     0    -1    -2     3     3     2     0    -1     0 [7,]     0     1     1     
 0     0    -1     0     1    -1     1     0     0 [8,]     1     0     0    -2     0 
     0    -2     1     1     0     0    -1 [9,]     1     0    -2     0     0    -2   
   2     2     0     1     0     0[10,]     1     0     0     0     0    -1     1     
 1     0     1     1     2[11,]     0    -1     1     1     0     0     0     1    -2 
     1     0     1[12,]     1     1     0     1    -1    -1     1     2     0     1   
   0     0[13,]     2     0    -1     1    -1    -3     4     1     0     1    -1   
  -2[14,]    -1     0    -1     2    -1    -1     1     0    -1     1     2     
 0[15,]     2     0     0    -2    -2     0     0     2     2     2     1    -1[16,] 
     0     0     0     1     0    -1     1     0     1     1     1    -1      [,26] 
 [,27] [,28] [,29] [,30] [,31] [,32] [1,]     0    -1    -1    -1    -2     0     
 1 [2,]    -2    -1    -1     1     0     1     2 [3,]     0     0    -1    -2     2 
    -2     1 [4,]     1     2     0     1    -1     0     1 [5,]     0     0     1   
   2    -4    -2     0 [6,]     0     1    -1     0    -1     2     0 [7,]    -1   
  -2    -1     1     0    -2     1 [8,]     1    -2     0     0    -2     1     
 0 [9,]    -2     0     0     0    -3     1     0[10,]     2    -2    -1    -1     1 
     2     0[11,]    -1    -1    -1    -1     1     1     2[12,]    -1     0     0   
   0    -1     0     1[13,]    -2     1    -1    -1    -2     2     0[14,]     0   
  -1    -1     0     0     2     2[15,]     1    -1     0     0     0     3     
 1[16,]     0     0     2     1     0     2     1

[R] Error in names-.default(`*tmp*`, value = nmstrata) :

2004-03-12 Thread Wolfgang Pauli
Hi,

I have a problem with aov(). I used it many times, but now I have new data, 
tried to use it in the same way. I get I strange Error message that i can't 
understand (see below). I guess it is caused by incompatible data types. The 
dataframe also looks ok to me.

I use:
spk =factor(rep(c(spk1,spk2,spk3,spk4,spk5,spk6,spk7,spk8), 
c(2,2,2,2,2,2,2,2)))
cs = factor(rep(c(yes,no),c(8,8)))
sub = factor(sort(spaeVP))
rati = stack(data.frame(arousal))
rati = rati[,1]
rating.df -  data.frame(sub, cs, spk, rati)
summary(aov(rati ~ cs*spk + Error(sub/(cs*spk)), data=rating.df))

I get this Error (after about 5sec):
Error in names-.default(`*tmp*`, value = nmstrata) : 
names attribute must be the same length as the vector

 rating.df
sub  cs  spk rati
1 5 yes spk1   -1
2 5 yes spk10
3 5 yes spk21
4 5 yes spk20
5 5 yes spk30
6 5 yes spk3   -1
7 5 yes spk4   -1
8 5 yes spk41
9 5  no spk50
...

Hope somebody can help me.

with best regards,

Wolfgang

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] newbie question on contrasts and aov

2004-01-29 Thread Wolfgang Pauli
In the meantime I figured out that the Difference-contrast is not quite what I 
was looking for. But I still have two questions

1) Why do I get different results for Helmert contrasts in SPSS and R. I guess 
the contrast matrixes of Helmert are about the same in SPSS and R. I probably 
make a mistake as i am a newbie to R. I thought that it might be, because I 
have a repaeted measures design. That's why I put the Error(sub) in the 
formula of aov. 

2)
I tried to make my own contrast matrix, to compute comparisons between 
adjacent factor levels, i.e. 1-2, 2-3 and 3-4. My matrix looks like this:
 [,1] [,2] [,3]
[1,]100
[2,]   -110
[3,]0   -11
[4,]00   -1

But then I get the same result as with contr.helmert(4). What is wrong I 
really don't get it!

Thank you,

Wolfgang Pauli

On Sunday January 11 2004 18:07, you wrote:
 Notice  `SPKType III Sum of Squares'.  I don't believe your contrasts are
 orthogonal, and R's are sequential sum of squares.

 Also, are you sure these are the same contrasts?  I presume this is
 contr.sdif from MASS (in which case it is churlish not to credit it), and
 SPSS's contrasts look more like Helmert contrasts from their labelling.

 Since it appears all your treatments are within subjects you do seem to be
 making life difficult for yourself. Although I would have done a simple
 fixed-effects analysis, applying summary.lm to the bottom stratum would
 give you simple t-tests for each contrast, including actual estimates of
 the magnitudes.

 On Sun, 11 Jan 2004, Wolfgang Pauli wrote:
  I try to move from SPSS to R/S and am trying to reproduce the results of
  SPSS in R. I calculated a one-way anova with spk as experimental factor
  and erp as depended variable.
  The result of the Anova are the same concearning the mean square, F and p
  values. But I also wanted to caculate the contr.sdif(4) contrast on spk.
  The results are completely different now. I hope anybody can help me.
 
  Thanks, Wolfgang
 
  This is what I get in SPSS:
  Tests of Within-Subjects Contrasts
  Measure: MEASURE_1
  Source  SPKType III Sum of Squares  df  Mean Square F  
   Sig.
  SPK Level 2 vs. Level 1 3,493   1   3,493   2,026   ,178
  Level 3 vs. Previous20,358  1   20,358  10,168  ,007
  Level 4 vs. Previous18,808  1   18,808  15,368  ,002
  Error(SPK)  Level 2 vs. Level 1 22,414  13  1,724
  Level 3 vs. Previous26,030  13  2,002
  Level 4 vs. Previous15,911  13  1,224
 
  This is the result in R:
  Error: sub
Df Sum Sq Mean Sq F value Pr(F)
  Residuals 13 205.79   15.83
 
  Error: Within
Df Sum Sq Mean Sq F valuePr(F)
  spk3 29.425   9.808  9.4467 8.055e-05 ***
  spk: p   1  1.747   1.747  1.6821 0.2022649
  spk: q   1 13.572  13.572 13.0719 0.0008479 ***
  spk: r   1 14.106  14.106 13.5861 0.0006915 ***
  Residuals 39 40.493   1.038
  ---
  Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
 
 
 
  Spk.df - data.frame(sub,spk,erp)
  subset(Spk.df, subset=(sub!=14oddball  sub!=18odd  sub!=19odd 
  sub!=20oddball)) - Spk.selected.df
  contrasts(Spk.selected.df$spk) - contr.sdif(4)
  aov(erp ~ spk + Error(sub), data=Spk.selected.df) - Spk.aov
  summary(Spk.aov,data=Spk.selected.df,split=list(spk=list(p=1,q=2,r=3)))
 
  this is the the beginning of the dataframe, which I use:
   sub  spkerp
  1  10oddball spk1  2.587
  2  11oddball spk1 -0.335
  3  12oddball spk1  5.564
  5  15oddball spk1  0.691
  6  17oddball spk1 -1.846
  10 21oddball spk1  1.825
  11 22oddball spk1  0.370
  12  2oddball spk1  3.234
  13  3oddball spk1  1.462
  14  5oddball spk1  2.535
  15  6oddball spk1  9.373
  16  7oddball spk1  2.132
  17  8oddball spk1 -0.518
  18  9oddball spk1  2.450
  19 10oddball spk2  2.909
  20 11oddball spk2  0.708
  21 12oddball spk2  4.684
  23 15oddball spk2  3.599
  ...
 
  __
  [EMAIL PROTECTED] mailing list
  https://www.stat.math.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide!
  http://www.R-project.org/posting-guide.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] newbie question on contrasts and aov

2004-01-11 Thread Wolfgang Pauli
I try to move from SPSS to R/S and am trying to reproduce the results of SPSS 
in R. I calculated a one-way anova with spk as experimental factor and erp 
as depended variable. 
The result of the Anova are the same concearning the mean square, F and p 
values. But I also wanted to caculate the contr.sdif(4) contrast on spk. The 
results are completely different now. I hope anybody can help me.

Thanks, Wolfgang

This is what I get in SPSS:
Tests of Within-Subjects Contrasts
Measure: MEASURE_1 
Source  SPKType III Sum of Squares  df  Mean Square F   Sig.
SPK Level 2 vs. Level 1 3,493   1   3,493   2,026   ,178
Level 3 vs. Previous20,358  1   20,358  10,168  ,007
Level 4 vs. Previous18,808  1   18,808  15,368  ,002
Error(SPK)  Level 2 vs. Level 1 22,414  13  1,724   
Level 3 vs. Previous26,030  13  2,002  
 
Level 4 vs. Previous15,911  13  1,224  
 

This is the result in R:
Error: sub
  Df Sum Sq Mean Sq F value Pr(F)
Residuals 13 205.79   15.83

Error: Within
  Df Sum Sq Mean Sq F valuePr(F)
spk3 29.425   9.808  9.4467 8.055e-05 ***
spk: p   1  1.747   1.747  1.6821 0.2022649
spk: q   1 13.572  13.572 13.0719 0.0008479 ***
spk: r   1 14.106  14.106 13.5861 0.0006915 ***
Residuals 39 40.493   1.038
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1



Spk.df - data.frame(sub,spk,erp)
subset(Spk.df, subset=(sub!=14oddball  sub!=18odd  sub!=19odd  
sub!=20oddball)) - Spk.selected.df
contrasts(Spk.selected.df$spk) - contr.sdif(4)
aov(erp ~ spk + Error(sub), data=Spk.selected.df) - Spk.aov
summary(Spk.aov,data=Spk.selected.df,split=list(spk=list(p=1,q=2,r=3)))

this is the the beginning of the dataframe, which I use:
 sub  spkerp
1  10oddball spk1  2.587
2  11oddball spk1 -0.335
3  12oddball spk1  5.564
5  15oddball spk1  0.691
6  17oddball spk1 -1.846
10 21oddball spk1  1.825
11 22oddball spk1  0.370
12  2oddball spk1  3.234
13  3oddball spk1  1.462
14  5oddball spk1  2.535
15  6oddball spk1  9.373
16  7oddball spk1  2.132
17  8oddball spk1 -0.518
18  9oddball spk1  2.450
19 10oddball spk2  2.909
20 11oddball spk2  0.708
21 12oddball spk2  4.684
23 15oddball spk2  3.599
...

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Huynh-Feldt correction

2003-12-20 Thread Wolfgang Pauli
Dear All,

I tried to help myself by searching in newsgroups etc. I found a test for
epsilon in a newsgroup (see attachement). I wrote a little skript to update
the summary.anova if epsilon  0.75.
Although I doublechecked my statistic book for the formula, the result is
always the half of the epsilon calculated by SPSS. It is really strange. If I
multiply espilon by two, I get the right results...

regards,

WP

#begin -

correctSummary - function(sum,eps) {
# eps is the epsilon-value returned by function hf
# sum is the summary.aov object in which the Huynh-Fldt correction has to be
down
len - length(sum)
newSum - sum
for (i in 2: len) {
newSum[[i]][[1]][4,] - newSum[[i]][[1]][2,]
newSum[[i]][[1]][3,] - newSum[[i]][[1]][2,]
newSum[[i]][[1]][2,] - newSum[[i]][[1]][1,]
rownames(newSum[[i]][[1]]) - c(rownames(newSum[[i]][[1]][1,]),
Huynh-Feldt, rownames(newSum[[i]][[1]][2,]), Huynh-Feldt)
newSum[[i]][[1]][2,][1] - newSum[[i]][[1]][2,][1]*epsilon*2
newSum[[i]][[1]][4,][1] - newSum[[i]][[1]][4,][1]*epsilon*2
newSum[[i]][[1]][2,][3] - newSum[[i]][[1]][2,][2]/newSum[[i]][[1]][2,][1]
newSum[[i]][[1]][4,][3] - newSum[[i]][[1]][4,][2]/newSum[[i]][[1]][4,][1]
newSum[[i]][[1]][2,][4] - newSum[[i]][[1]][2,][3]/newSum[[i]][[1]][4,][3]

newSum[[i]][[1]][2,][5] - pf(as.numeric(newSum[[i]][[1]][2,][4]),
as.numeric(newSum[[i]][[1]][2,][1]), as.numeric(newSum[[i]][[1]][4,][1]),
lower.tail = FALSE)
}
newSum

}

hf - function(m){
# m is a matrix with subjects as rows and conditions as columns
# note that checking for worst case scenarios F correction first
 might # be a good idea using J/(J-1) as the df correction factor
n- length(m[,1])
J-length(m[1,])
X-cov(m)
r- length(X[,1])
D-0
for (i in 1: r) D- D+ X[i,i]
D-D/r
SPm- mean(X)
SPm2- sum(X^2)
SSrm-0
for (i in 1: r) SSrm- SSrm + mean(X[i,])^2
epsilon - (1/(J-1))*((J^2*(D-SPm)^2)/(SPm2 - 2*J*SSrm + J^2*SPm^2))
epsilon
}


# 

On Thursday December 18 2003 12:00, Wolfgang Pauli wrote:
 Dear R-helpers,

 Does anybody know, whether there is an option to tell aov/anova, or do
 something similar, to get a Huynh-Feldt correction of dfs in the aov/anova
 function?

 Thanks in advance!

 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


[R] Huynh-Feldt correction

2003-12-18 Thread Wolfgang Pauli
Dear R-helpers,

Does anybody know, whether there is an option to tell aov/anova, or do 
something similar, to get a Huynh-Feldt correction of dfs in the aov/anova 
function?

Thanks in advance!

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help