Why do variations of this t.test require different coding? (R) -


new r , trying head around it's coding (new coding in general)

my question is, running t-tests (paired , independent) have change formula recognise columns. following both work; 'paired' code not work if styled 'independent' code (with data = '').

independent: t.test(nicotine ~ brand, data = nicotine, alternative='two.sided', conf.level=.95, var.equal=false)

paired: with(omega3, t.test(before, after, paired = true, alternative='greater', conf.level=.95))

why happen? ideally i'd prefer not use with formula, cannot understand why not recognize "before" , "after" when add argument data = omega3

any insight appreciated.

thom

it has way data used function. when you're using formula, you're telling r: "use variable predictor (independent var), , other 1 outcome (dependent var)". in case of independent samples t-test, you'd have:

continuous.variable  ~  dichotomous.variable (outcome/dependent)     (predictor/independent) 

with paired-samples, have no such thing "predictor" (or more largely speaking "explanatory variable"). have 2 columns wish compare against 1 another.

so can see formula notation nice feature of r, 1 cannot use in every situation.

besides, there alternatives using with function :

t.test(before, after, paired = true, alternative='greater', conf.level=.95, data=omega3) # or t.test(omega3$before, omega3$after, paired = true, alternative='greater', conf.level=.95) 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -