anova

ANOVA in python using pandas dataframe with statsmodels or scipy?

↘锁芯ラ 提交于 2019-12-03 01:09:17
I want to use the Pandas dataframe to breakdown the variance in one variable. For example, if I have a column called 'Degrees', and I have this indexed for various dates, cities, and night vs. day, I want to find out what fraction of the variation in this series is coming from cross-sectional city variation, how much is coming from time series variation, and how much is coming from night vs. day. In Stata I would use Fixed effects and look at the R^2. Hopefully my question makes sense. Basically, what I want to do, is find the ANOVA breakdown of "Degrees" by three other columns. cphlewis I set

aov() error term in R: what's the difference bw Error(id) and Error(id/timevar) specification?

风格不统一 提交于 2019-12-02 22:07:50
What is the difference between the aov(depvar~timevar+Error(id)) and the aov(depvar~timevar+Error(id/timevar)) formula specifications? These two variants produce slightly different results. The same question was once asked here: https://stats.stackexchange.com/questions/60108/how-to-write-the-error-term-in-repeated-measures-anova-in-r However, I'd like to repeat it with a more appropriate example. Here is an example that I created: var=rep(NA,180) id=rep(1:20,each=180/20) group=rep(rep(1:2,each=9),180/(9*2)) time1=rep(rep(1:3,each=3),180/(3*3)) time2=rep(c(8,15,20),180/3) var[group==1&time1==1

How can I force dropping intercept or equivalent in this linear model?

允我心安 提交于 2019-12-02 10:47:25
Consider the following table : DB <- data.frame( Y =rnorm(6), X1=c(T, T, F, T, F, F), X2=c(T, F, T, F, T, T) ) Y X1 X2 1 1.8376852 TRUE TRUE 2 -2.1173739 TRUE FALSE 3 1.3054450 FALSE TRUE 4 -0.3476706 TRUE FALSE 5 1.3219099 FALSE TRUE 6 0.6781750 FALSE TRUE I'd like to explain my quantitative variable Y by two binary variables (TRUE or FALSE) without intercept. The argument of this choice is that, in my study, we can't observe X1=FALSE and X2=FALSE at the same time, so it doesn't make sense to have a mean, other than 0, for this level. With intercept m1 <- lm(Y~X1+X2, data=DB) summary(m1)

How to do ANCOVA in R?

試著忘記壹切 提交于 2019-12-02 08:09:07
问题 I have a dataframe with three columns: data$input, data$output and data$category. Both input and output are continuous numerics, and categories are discrete characters. I know ANCOVA is a method that analyzes the effect of input on output while controlling for the effect of category. However I could not find the exact command to do for this online. Here is a small example of how the data would look like: input output category 1 0.4 0.55 A 2 0.5 0.66 A 3 0.6 0.57 A 4 0.3 0.23 B 5 0.4 0.53 B 6

How to get residuals from Repeated measures ANOVA model in R

巧了我就是萌 提交于 2019-12-02 06:28:35
问题 Normally from aov() you can get residuals after using summary() function on it. But how can I get residuals when I use Repeated measures ANOVA and formula is different? ## as a test, not particularly sensible statistically npk.aovE <- aov(yield ~ N*P*K + Error(block), npk) npk.aovE summary(npk.aovE) Error: block Df Sum Sq Mean Sq F value Pr(>F) N:P:K 1 37.0 37.00 0.483 0.525 Residuals 4 306.3 76.57 Error: Within Df Sum Sq Mean Sq F value Pr(>F) N 1 189.28 189.28 12.259 0.00437 ** P 1 8.40 8

How to do ANCOVA in R?

可紊 提交于 2019-12-02 05:26:13
I have a dataframe with three columns: data$input, data$output and data$category. Both input and output are continuous numerics, and categories are discrete characters. I know ANCOVA is a method that analyzes the effect of input on output while controlling for the effect of category. However I could not find the exact command to do for this online. Here is a small example of how the data would look like: input output category 1 0.4 0.55 A 2 0.5 0.66 A 3 0.6 0.57 A 4 0.3 0.23 B 5 0.4 0.53 B 6 0.7 0.75 B 7 1.1 1.31 C 8 0.9 1.01 C 9 0.8 0.58 C 10 0.5 0.34 C What commands should I input to perform

How to get residuals from Repeated measures ANOVA model in R

好久不见. 提交于 2019-12-02 00:57:32
Normally from aov() you can get residuals after using summary() function on it. But how can I get residuals when I use Repeated measures ANOVA and formula is different? ## as a test, not particularly sensible statistically npk.aovE <- aov(yield ~ N*P*K + Error(block), npk) npk.aovE summary(npk.aovE) Error: block Df Sum Sq Mean Sq F value Pr(>F) N:P:K 1 37.0 37.00 0.483 0.525 Residuals 4 306.3 76.57 Error: Within Df Sum Sq Mean Sq F value Pr(>F) N 1 189.28 189.28 12.259 0.00437 ** P 1 8.40 8.40 0.544 0.47490 K 1 95.20 95.20 6.166 0.02880 * N:P 1 21.28 21.28 1.378 0.26317 N:K 1 33.14 33.14 2.146

Anova, for loop to apply function

大城市里の小女人 提交于 2019-12-01 20:14:07
>str(set) 'data.frame': 1000 obs. of 6 variables: $ ID : Factor .. $ a : Factor .. $ b: Factor .. $ c: Factor .. $ dat : num .. $ contrasts : Ord.factor .. >X [1] "a" "b" "c" for (i in 1 :length(X) ){ my=X[i] f=as.formula(paste("dat~contrasts*", paste(my,"Error(ID/(contrasts))",sep="+"))) sum = summary( aov (f, data =set)) } X can be very huge, so was thinking about an apply function instead of for-loop.Is it possible in this case?? I tried this: apply( as.matrix(X), 1, function(i){ summary(aov(as.formula(paste("dat~contrasts*", paste(i, "Error(ID/(contrasts))", sep="+"))), data=set)) } ) But

extracting t value out of pairwise.t.test

折月煮酒 提交于 2019-12-01 19:06:51
I would like to know if I could extract t values out of the pairwise.t.test function since it is only reporting the p values. I used the pairwise.t.test() for multiple comparisons after running a repeated-measures anova which reported a significant main effect. Thank you alot in advance! There are some simple things to try when trying to figure something like this out (there is, of course, no guarantee that they will work in any given instance). The first thing to try is to look at the documentation ( ?pairwise.t.test ) and see what's listed under Value . In this case it only says: Object of

extracting t value out of pairwise.t.test

随声附和 提交于 2019-12-01 18:30:41
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . I would like to know if I could extract t values out of the pairwise.t.test function since it is only reporting the p values. I used the pairwise.t.test() for multiple comparisons after running a repeated-measures anova which reported a significant main effect. Thank you alot in advance! 回答1: There are some simple things to try when trying to figure something like this out