开发者

Significance in R

开发者 https://www.devze.com 2023-02-03 05:59 出处:网络
Ok, this is quite hard to explain, but I\'m at a complete loss what to do. I\'m a relative newcomer to R and although I can completely admire how powerful it is, I\'m not too good at actually using it

Ok, this is quite hard to explain, but I'm at a complete loss what to do. I'm a relative newcomer to R and although I can completely admire how powerful it is, I'm not too good at actually using it....

Basically, I have some very contrived data that I need to analyse (it wasn't me who chose this, I can assure you!). I have the right and left hand lengths of lots of people, as well as some numeric data that shows their sociability.

Now I would like to know if people who have significantly different lengths of hand are more or less sociable than those who have the same (leading into the research that 'symmetrical' people are more sociable and intelligent, etc.

I have got as far as loading the data into R, then I have no idea where to go from there. How on Earth do I start to separate those who are close to symmetrical to those who aren't to then start to do the analysis?


Ok, using Sacha's great advice, I did the cor.test and got the following:

P开发者_StackOverflow社区earson's product-moment correlation

data:  measurements$l.hand - measurements$r.hand and measurements$sociable 
t = 0.2148, df = 150, p-value = 0.8302
alternative hypothesis: true correlation is not equal to 0 
95 percent confidence interval:
 -0.1420623  0.1762437 
sample estimates:
       cor 
0.01753501

I have never used this test before, so am unsure how to intepret it...you wouldn't think I was on my fourth Scientific degree would you?! :(


A significance test is used to see if the aquired effect in the sample can be due to random error. It is not really usable for individual scores, but what you can do is standardize the differences.

If 'dat' is the name of your dataframe, containing the columns 'hand.left', 'hand.right' and 'social' then you can standardize the differences in this way:

stand=scale(dat$hand.left-dat$hand.right)

Then you can create a logical dummy vector indicating if a person has a likelihood of this difference given the sample:

dum=abs(stand)<1.96

Which you can then use in a t-test:

t.test(dat$social[dum],dat$social[!dum])

However, the problem with this is that due to the nature of standardizing the sample size in the equal hand group will be about 20 times larger then the inequal hand group, so you need a lot of observations. An alternative is to look at the correlation between sociability and the absolute hand differences:

cor.test(abs(dat$hand.left-dat$hand.right), dat$social)


Looks like a regression problem:

set.seed(1)
DF <- data.frame(lhand = rnorm(100, 15, sd = 2), rhand = rnorm(100, 15, sd = 2),
                 social = runif(100))
DF <- within(DF, handedness <- lhand - rhand)

mod <- lm(social ~ handedness, data = DF)
summary(mod)

Here this is no relationship (not suprising as these are just random data):

> summary(mod)

Call:
lm(formula = social ~ handedness, data = DF)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.51113 -0.25170 -0.02336  0.26161  0.52042 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.507240   0.030700  16.522   <2e-16 ***
handedness  -0.007896   0.011670  -0.677      0.5    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.3051 on 98 degrees of freedom
Multiple R-squared: 0.00465,    Adjusted R-squared: -0.005506 
F-statistic: 0.4579 on 1 and 98 DF,  p-value: 0.5002

For your real problem, ask yourself if a linear approximation between social and handedness might be appropriate. So plot the data:

plot(social ~ handedness, data = DF)

Does it look bivariate Gaussian?

If the linear relationship looks OK, fit the linear model and then check the residuals for problems (curved patterns, non-constant variance, strong deviation from normality). Then move on from there. If a linear approximation doesn't seem right, can you linearise the relationship with a transformation? If yes, try that, if not how about trying a GLM? etc. etc...


You should examine your data...

hist( measurements$social )

How does it look?... normal?

You might try regression

stand = scale( measurements$l.hand - measurements$r.hand )
m <- lm( measurements$social ~ stand )
m
summary(m)
anova(m)

You can also plot the model and it will give you diagnostics

plot(m)

Please type the phrase ?command (e.g. ?lm) for all of the commands that you try here. It will help you understand what is going on.

0

精彩评论

暂无评论...
验证码 换一张
取 消