Assistance with GLMM in either R or SPSS

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Assistance with GLMM in either R or SPSS

Sarah Thomas
Hi there! I am trying to figure out how I can analyze my data. Any help would
be greatly appreciated.

The dataset includes 72 participants who answered a question with a
dichotomous response (yes/no). There are two between-subject variables (age:
2 conditions - young/old, and Variable X: conditions- Up/Down,) and a within
subject variable (Variable Y: 3 conditions, A, B, and C). An example of the
dataset is attached as an image.

<http://spssx-discussion.1045642.n5.nabble.com/file/t341829/ExampleData.jpg>

Example Data frame code for R

Participant <- c('A','B','C')
Age <- c('Young', 'Young', 'Old')
VariableX <- c('Up', 'Up', 'Down')
ConditionA <- c('Yes', 'No', 'Yes')
ConditionB <- c('No', 'Yes', 'No')
ConditionC <- c('Yes', 'Yes', 'No')
ExampleData <- dataframe(Participant, Age, VariableX, ConditionA,
ConditionB, ConditionC)

I am trying to figure out what to run in order to see if there is an
interaction effect between age, Variable X and Variable Y on the binomial
response of participants.

I tried to run a GLMM (ominbus generalized mixed model with a binary
logistic regression function) with the binary response (yes/no) across
condition with pre-defined contrasts (Condition A-ConditionC,
ConditionB-ConditionC) as a within-subjects variables, and age (Young, old)
and condition Y (Up, Down) as between subject variables in SPSS. I am not
sure however if we did it correctly. I received no output data for the
significance value.

Any guidance on how to analyze and interpret the output would be greatly
appreciated!* I am happy to analyze these data either in SPSS or in R.*

Thanks!



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Assistance with GLMM in either R or SPSS

Bruce Weaver
Administrator
You'll have to restructure your data (with VARSTOCASES) so that there is one
row per observation of the outcome variable, like this:

ID Old Up Cond Y
1    0  1   1  1
1    0  1   2  0
1    0  1   3  1
2    1  0   1  1
2    1  0   2  1
2    1  0   3  0

Notice that I have used Cond (short for condition) to describe the variable
you called Y.  And I have used Y to refer to the outcome variable (as is the
convention).  Variables Old, Up and Y are all "indicator variables" with
1=Yes and 0=No.

HTH.


Sarah Thomas wrote

> Hi there! I am trying to figure out how I can analyze my data. Any help
> would
> be greatly appreciated.
>
> The dataset includes 72 participants who answered a question with a
> dichotomous response (yes/no). There are two between-subject variables
> (age:
> 2 conditions - young/old, and Variable X: conditions- Up/Down,) and a
> within
> subject variable (Variable Y: 3 conditions, A, B, and C). An example of
> the
> dataset is attached as an image.
>
> &lt;http://spssx-discussion.1045642.n5.nabble.com/file/t341829/ExampleData.jpg&gt; 
>
> Example Data frame code for R
>
> Participant <- c('A','B','C')
> Age <- c('Young', 'Young', 'Old')
> VariableX <- c('Up', 'Up', 'Down')
> ConditionA <- c('Yes', 'No', 'Yes')
> ConditionB <- c('No', 'Yes', 'No')
> ConditionC <- c('Yes', 'Yes', 'No')
> ExampleData <- dataframe(Participant, Age, VariableX, ConditionA,
> ConditionB, ConditionC)
>
> I am trying to figure out what to run in order to see if there is an
> interaction effect between age, Variable X and Variable Y on the binomial
> response of participants.
>
> I tried to run a GLMM (ominbus generalized mixed model with a binary
> logistic regression function) with the binary response (yes/no) across
> condition with pre-defined contrasts (Condition A-ConditionC,
> ConditionB-ConditionC) as a within-subjects variables, and age (Young,
> old)
> and condition Y (Up, Down) as between subject variables in SPSS. I am not
> sure however if we did it correctly. I received no output data for the
> significance value.
>
> Any guidance on how to analyze and interpret the output would be greatly
> appreciated!* I am happy to analyze these data either in SPSS or in R.*
>
> Thanks!
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: Assistance with GLMM in either R or SPSS

Art Kendall
How was age originally measured?  Did it come to you already coarsened?

Young = under 65
Old = 65 and older?

Young = under 36 months
Old = 36 months and older?



-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Assistance with GLMM in either R or SPSS

Kornbrot, Diana
In reply to this post by Sarah Thomas
Hi Sarah

Am working on comparing packages for this problem, comparing SPSS and R
1st
As Bruce states get data in long form
ID Old Up Cond Y
1    0  1   1  1
1    0  1   2  0
1    0  1   3  1
2    1  0   1  1
2    1  0   2  1
2    1  0   3  0
Makes sure all variables are nominal for SPSS
Then I would be most grateful if you would send me long data in CSV or .sav
SPSS analysis
1.1. Set preferences > output > display>output display pivots and charts. Makes output easier to read
1.2.  Set preferences > viewer> log > shown. This ensures you can share syntax with others
2. Analysis > mixed models> generalised linear. You will get a lot of tabs
3 Data structure tab
3.1 Data structure > effects: id  = subject; repeated measures  = Up, Cond
3.2 Data structure > covariance = unstructured
4. Fields and effect tab
4.1 Target = Y. It will then default to logistic because Y is nominal
4.2 Fixed: insert Old, Up, Cond and all 2 way and 3 way interactions
5 Build tab. This only affects df for F tests. Kenward-Rogers is currently flavour of the month, residual is conservative
6. Model options tab. Should see all main and interactions listed. Needed to get means and comparison
6.1 Tick all of them
6.2 Choses pairwise contrasts for all of them
7. RUN
SPSS output, wharf massive output, t is needed?
Model describes variables and AIC<BIC for model fit
Fixed gives the F-values, including the interaction - which you were requesting
Estimated means. Provided separately for all main and interaction effects with pretty pictures
Good luck!
R maybe typos in this but should be easy to correct
Make sure you have R studio
1. Launch R studio
1.1 Make sure you have all necessary packages, I suggest
library(haven # its about file loading
library(readxl) #ensures you can read in data
library(tidyverse) #supposed to make output pretty
ibrary(lme4) #has needed function glmer
library(emmeans) # to get means
library(dbplyr) #needed for graphs
library(rmarkdown) # for refines output, not needed
library(knitr) ) # for refines output, not needed
1.2 tenure lme4 and emmeans are ticked ob right under packages
2. Load your data from R studio file menu
2.1 import> spss> e.e. sarah.sav
browse to find it , then import
3. Tell R about your data
# Assign columns to contain categorical factor predictor variables
sarah[c(1,2,3,4,5 )] <- lapply(Sarah[c(1,2,3,4,5)], factor)
#Assign contrasts
contrasts(sarah$Up) <- contr.sum(2)
contrasts(sarah$Cond) <- contr.sum(2)
contrasts(Sarah $Old) <- contr.sum(2)
4. perform analysis, with results in object res
res <- glmer(Y ~ Old|Up|Cond + (Up|Cond|ID), data=Sarah, family=binomial(link="logit”)) #does analysis
# if correct you will get a friendly “>”. Now you need R to divulge its secrets
anova(res) # gets the F table
descr <- means(res, ~ Old|Up|Cond, data=sarah) # means and SEs
descr # outputs means and YEs
pairs (descr) #gets all pairwise comparisons 
5. GET graphs - optional - may not work
emmpi(descr, ~ Old|Up|Cond, data=Sarah)
6. Copu output to WORD and/or EXCEL
Good luck?
NOW WHAT?
SPSS and R may [probably will] give different answers
Probably differences are small 
 I would very much like to see them
Please send me your output
Help from SPSS community. Please
a. Who to trust? SPSS or R
What is caysbg differences?
b. Would much appreciate R code that duplicates SPSS as described above

best

Diana




On 28 Aug 2020, at 05:39, Sarah Thomas <[hidden email]> wrote:

Hi there! I am trying to figure out how I can analyze my data. Any help would
be greatly appreciated.

The dataset includes 72 participants who answered a question with a
dichotomous response (yes/no). There are two between-subject variables (age:
2 conditions - young/old, and Variable X: conditions- Up/Down,) and a within
subject variable (Variable Y: 3 conditions, A, B, and C). An example of the
dataset is attached as an image.

<http://spssx-discussion.1045642.n5.nabble.com/file/t341829/ExampleData.jpg>

Example Data frame code for R

Participant <- c('A','B','C')
Age <- c('Young', 'Young', 'Old')
VariableX <- c('Up', 'Up', 'Down')
ConditionA <- c('Yes', 'No', 'Yes')
ConditionB <- c('No', 'Yes', 'No')
ConditionC <- c('Yes', 'Yes', 'No')
ExampleData <- dataframe(Participant, Age, VariableX, ConditionA,
ConditionB, ConditionC)

I am trying to figure out what to run in order to see if there is an
interaction effect between age, Variable X and Variable Y on the binomial
response of participants.

I tried to run a GLMM (ominbus generalized mixed model with a binary
logistic regression function) with the binary response (yes/no) across
condition with pre-defined contrasts (Condition A-ConditionC,
ConditionB-ConditionC) as a within-subjects variables, and age (Young, old)
and condition Y (Up, Down) as between subject variables in SPSS. I am not
sure however if we did it correctly. I received no output data for the
significance value.

Any guidance on how to analyze and interpret the output would be greatly
appreciated!* I am happy to analyze these data either in SPSS or in R.*

Thanks!



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

____________
University of Hertfordshire
College Lane, Hatfield, Hertfordshire AL10 9AB, UK
+44 (0) 208 444 2081
+44 (0) 7403 18 16 12
[hidden email]
http://dianakornbrot.wordpress.com/
skype:  kornbrotme
Save our in-boxes! http://emailcharter.org
 __________________







===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Assistance with GLMM in either R or SPSS

Kornbrot, Diana
In reply to this post by Bruce Weaver
Thanks 

Can be different? They always are
But ia ma veery specific in what I want to do
Here is SPSS syntax of 2 possibilities, with just 2 levels
Already know that most packages, e.g. SPSS and R, give different results for paired comparisons within 3 levels and paired comparisons with just 2 levels 
Sop staying with 2 levels and being VERY specific
SPSS
GENLINMIXED
  /DATA_STRUCTURE SUBJECTS=pno REPEATED_MEASURES=wiithin COVARIANCE_TYPE=UNSTRUCTURED
  /FIELDS TARGET=freqY TRIALS=FIELD(Nmax)  OFFSET=NONE
  /TARGET_OPTIONS DISTRIBUTION=BINOMIAL LINK=LOGIT
  /FIXED  EFFECTS=wiithin USE_INTERCEPT=TRUE
  /BUILD_OPTIONS TARGET_CATEGORY_ORDER=ASCENDING INPUTS_CATEGORY_ORDER=ASCENDING MAX_ITERATIONS=100 CONFIDENCE_LEVEL=95 DF_METHOD=SATTERTHWAITE COVB=MODEL PCONVERGE=0.000001(ABSOLUTE) SCORING=0 SINGULAR=0.000000000001
  /EMMEANS TABLES=wiithin COMPARE=wiithin CONTRAST=PAIRWISE
  /EMMEANS_OPTIONS SCALE=TRANSFORMED PADJUST=LSD.
 
Has within factor in data structure with unstructured covariance
It looks simple but what is R code?
Have not been able  to discover after many attempts
Its what I have always recommended  
Or
*Generalized Linear Mixed Models.
GENLINMIXED
  /DATA_STRUCTURE SUBJECTS=pno
  /FIELDS TARGET=freqY TRIALS=FIELD(Nmax)  OFFSET=NONE
  /TARGET_OPTIONS DISTRIBUTION=BINOMIAL LINK=LOGIT
  /FIXED  EFFECTS=wiithin USE_INTERCEPT=TRUE
  /RANDOM EFFECTS=wiithin USE_INTERCEPT=FALSE SUBJECTS=pno COVARIANCE_TYPE=UNSTRUCTURED SOLUTION=FALSE
  /BUILD_OPTIONS TARGET_CATEGORY_ORDER=ASCENDING INPUTS_CATEGORY_ORDER=ASCENDING MAX_ITERATIONS=100 CONFIDENCE_LEVEL=95 DF_METHOD=SATTERTHWAITE COVB=MODEL PCONVERGE=0.000001(ABSOLUTE) SCORING=0 SINGULAR=0.000000000001
  /EMMEANS TABLES=wiithin COMPARE=wiithin CONTRAST=PAIRWISE
  /EMMEANS_OPTIONS SCALE=TRANSFORMED PADJUST=LSD.

Has within factor  as random effect with unstructured covariance
It gives very similar, but not identical to following in R
R
lgt12s <- glmer(cbind(freq,Nmax-freq) ~ wiithin + (wiithin|pno), data=kex12,family=binomial(link="logit"))
anova(lgt12s)
lgt12ms<-emmeans(lgt12s, ~wiithin,data =kex12)
lgt12ms
pairs(lgt12ms)
summary(lgt12s)
Here is output for 3 models
Measure SPSS-data structure 2 levels SPSS-random 2 levels R lgt slope 2 level
F 66.39 63.66 66.40
df1 1.0 1.0 1.0
w1mean-p .3050 .2800 .2670
w2mean-P .1420 .1230 .1081
w1se-p .0210 .0230 .0235
w2se-p .0130 .0120 .0126
diff-p .1620 .1570 .1589
diffse-p .0210 .0220  
t-pairwise 7.816 7.245 7.438
AIC 723.300 759.800 1051.5
BIC 733.500 770.100 1068.8

IMHO, SPSS within as random should be identical to within as repeated in data structure
Please can anyone explain WHY they are not the same

There must be SOMEONE out there  who understands both R and SPSS who can explain what is happening
I note that within in data structure has lower AIC, BIC than within in random
So please, please how can one do 1st SPSS model in R?

HELP

Have also copied in Mark and Thomas, who I know to be R experts

Best

Diana
  


On 31 Aug 2020, at 14:07, Jon Peck <[hidden email]> wrote:

The answer would depend on the specifics of the model.  Even within R, different mixed model packages can give different answers.

On Mon, Aug 31, 2020 at 12:47 AM Kornbrot, Diana <[hidden email]> wrote:
Hi Bruce, Jon

Do you know how to perform same GLLM in R as SPPS performs win MIXED
You are clearly both experts!
Am concerned that get different results in R and SPSS
best
Diana

On 28 Aug 2020, at 14:22, Bruce Weaver <[hidden email]> wrote:

You'll have to restructure your data (with VARSTOCASES) so that there is one
row per observation of the outcome variable, like this:

ID Old Up Cond Y
1    0  1   1  1
1    0  1   2  0
1    0  1   3  1
2    1  0   1  1
2    1  0   2  1
2    1  0   3  0

Notice that I have used Cond (short for condition) to describe the variable
you called Y.  And I have used Y to refer to the outcome variable (as is the
convention).  Variables Old, Up and Y are all "indicator variables" with
1=Yes and 0=No.

HTH.


Sarah Thomas wrote
Hi there! I am trying to figure out how I can analyze my data. Any help
would
be greatly appreciated.

The dataset includes 72 participants who answered a question with a
dichotomous response (yes/no). There are two between-subject variables
(age:
2 conditions - young/old, and Variable X: conditions- Up/Down,) and a
within
subject variable (Variable Y: 3 conditions, A, B, and C). An example of
the
dataset is attached as an image.

&lt;http://spssx-discussion.1045642.n5.nabble.com/file/t341829/ExampleData.jpg&gt;

Example Data frame code for R

Participant <- c('A','B','C')
Age <- c('Young', 'Young', 'Old')
VariableX <- c('Up', 'Up', 'Down')
ConditionA <- c('Yes', 'No', 'Yes')
ConditionB <- c('No', 'Yes', 'No')
ConditionC <- c('Yes', 'Yes', 'No')
ExampleData <- dataframe(Participant, Age, VariableX, ConditionA,
ConditionB, ConditionC)

I am trying to figure out what to run in order to see if there is an
interaction effect between age, Variable X and Variable Y on the binomial
response of participants.

I tried to run a GLMM (ominbus generalized mixed model with a binary
logistic regression function) with the binary response (yes/no) across
condition with pre-defined contrasts (Condition A-ConditionC,
ConditionB-ConditionC) as a within-subjects variables, and age (Young,
old)
and condition Y (Up, Down) as between subject variables in SPSS. I am not
sure however if we did it correctly. I received no output data for the
significance value.

Any guidance on how to analyze and interpret the output would be greatly
appreciated!* I am happy to analyze these data either in SPSS or in R.*

Thanks!



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@.UGA

(not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

____________
University of Hertfordshire
College Lane, Hatfield, Hertfordshire AL10 9AB, UK
+44 (0) 208 444 2081
+44 (0) 7403 18 16 12
[hidden email]
http://dianakornbrot.wordpress.com/
skype:  kornbrotme
Save our in-boxes! http://emailcharter.org
 __________________









--
Jon K Peck
[hidden email]


____________
University of Hertfordshire
College Lane, Hatfield, Hertfordshire AL10 9AB, UK
+44 (0) 208 444 2081
+44 (0) 7403 18 16 12
[hidden email]
http://dianakornbrot.wordpress.com/
skype:  kornbrotme
Save our in-boxes! http://emailcharter.org
 __________________







===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD