Empty rows in SPSS for anova output - spss

I am trying to run a 4 way mixed ANOVA however some rows come up empty for some reason and I don't know why. Below is a sample of one of the output tables
GLM NormalizedJerk_102 NormalizedJerk_104 BY Test GROUP condition
/WSFACTOR=factor1 2 Polynomial
/METHOD=SSTYPE(3)
/POSTHOC=GROUP condition(BONFERRONI)
/EMMEANS=TABLES(OVERALL)
/EMMEANS=TABLES(factor1) COMPARE ADJ(BONFERRONI)
/EMMEANS=TABLES(Test) COMPARE ADJ(BONFERRONI)
/EMMEANS=TABLES(GROUP) COMPARE ADJ(BONFERRONI)
/EMMEANS=TABLES(condition) COMPARE ADJ(BONFERRONI)
/EMMEANS=TABLES(Test*GROUP)
/EMMEANS=TABLES(Test*condition)
/EMMEANS=TABLES(Test*factor1) compare(factor1)adj(BONFERRONI)
/EMMEANS=TABLES(GROUP*condition)
/EMMEANS=TABLES(GROUP*factor1) compare(factor1)adj(BONFERRONI)
/EMMEANS=TABLES(condition*factor1) compare(factor1)adj(BONFERRONI)
/EMMEANS=TABLES(Test*GROUP*condition)
/EMMEANS=TABLES(Test*GROUP*factor1) compare(factor1)adj(BONFERRONI)
/EMMEANS=TABLES(Test*condition*factor1) compare(factor1)adj(BONFERRONI)
/EMMEANS=TABLES(GROUP*condition*factor1) compare(factor1)adj(BONFERRONI)
/EMMEANS=TABLES(Test*GROUP*condition*factor1) compare(factor1)adj(BONFERRONI)
/PRINT=ETASQ
/CRITERIA=ALPHA(.05)
/WSDESIGN=factor1
/DESIGN=Test GROUP condition Test*GROUP Test*condition GROUP*condition Test*GROUP*condition.

You've probably resolved this by now, and I can't be certain without seeing your data, but it looks like a colinearity issue. SPSS produces blank cells for independent variables which are perfectly predictable from another independent variable. Your output is what you'd expect to see if everyone who was assigned a score of 0 for factor1 was also assigned a score of 0 for Time, everyone who was assigned a score of 1 for factor1 was also assigned a score of 1 for Time, and so on.

Related

how to select SpatRaster layers from their names?

I've got a SpatRaster of (150 x 150 x 1377) that shows temporal evolution of precipitations. Each layer is a given hour in a 2-month interval, but some hours are missing, and the dataset isn't continuous. The layers names are strings as "YYYYMMDDhhmm".
I need to find the mean value every three hours even on whole intervals or on missing-data intervals. On entire ones I want to average three data and on missing-data ones I would like to average two of them or, if two are missing, to select the unique value as the averaged one.
How can I use data names to select how to act?
I've already tried this code but I'm averaging on three continuous layers by index and not by hours. How can I convert names in DateTime form from "tidyverse" in order to use rollapply() to see if two steps back I find the DateTime I am expecting? Is there any other method to check this out?
HSAF=rast(c((paste0(resfolder, "HSAF_final1_5.tif")),(paste0(resfolder, "HSAF_final6_10.tif")),(paste0(resfolder, "HSAF_final11_15.tif")),
(paste0(resfolder, "HSAF_final16_20.tif")),(paste0(resfolder, "HSAF_final21_25.tif")),(paste0(resfolder, "HSAF_final26_30.tif")),
(paste0(resfolder, "HSAF_final31_N04.tif")),(paste0(resfolder, "HSAF_finalN05_N08.tif")),(paste0(resfolder, "HSAF_finalN09_N13.tif")),
(paste0(resfolder, "HSAF_finalN14_N18.tif")),(paste0(resfolder, "HSAF_finalN19_N23.tif")),(paste0(resfolder, "HSAF_finalN24_N28.tif")),
(paste0(resfolder, "HSAF_finalN29_N30.tif"))))
index=names(HSAF)
j=2
for (i in seq(1,3, by=3))
{third_el<- HSAF[index[i+j]]
second_el <- HSAF[index[i+j-1]]
first_el<- HSAF[index[i+j-2]]
newraster<- c(first_el, second_el, third_el)
newraster<- mean(newraster, filename=paste0(tempfile(), ".tif"))
names(newraster)<- paste0(index[i+j-2],index[i+j-1],index[i+j])
}
for (i in seq(4,1374 , by=3))
{ third_el<- HSAF[index[i+j]]
second_el <- HSAF[index[i+j-1]]
first_el<- HSAF[index[i+j-2]]
subraster<- c(first_el, second_el, third_el)
subraster<- mean(subraster, filename=paste0(tempfile(), ".tif"))
names(subraster)<- paste0(index[i+j-2],index[i+j-1],index[i+j])
add(newraster)<- subraster
}

SPSS - Filter columns based on specific criteria

I have a dataset (See below) where I want to filter out any observations where there is only a 1 in the McDonalds column, such as for ID#3 (I do not want Mcdonalds in my analyses). I want to keep any observations where there is a 1 in other columns (eventhough there is a 1 in the McDonalds column - such as ID #1-2). I have tried using the select cases option, and just putting McDonalds=0, but this filters out any observations where there are 1s in the other columns as well. Below is a sample of my dataset, I actually have many more columns and was trying to avoid having to individually name every other column in the "Select Cases" option in SPSS. Would anyone be able to help me please? Thanks.
Data:
To avoid naming each of the other columns separately you can use to in the syntax. Also, basically, you want to keep lines that have 1 in any of the other columns regardless of the value in the Mcdonald's column, so there is no need to mention it in the syntax.
So say for example that your column names are McDonalds, RedBull, var3, var4, var5, TacoBell, you could use either of these following options:
select if any(1, RedBull to TacoBell).
or this :
select if sum(RedBull to TacoBell)>1.
Note: using the to convention requires that the relevant variables be contiguous in the data.
You just need to add the "OR" operator (which is the vertical bar: |) between all the mentioned conditions.
So basically, you want to keep the cases when McDonalds = 0 | RedBull = 1 | TacoBell = 1.
You can either copy the above line into the Select cases -> If option, or write the following lines into the SPSS syntax file, replacing the DataSet1 for the name of your dataset:
DATASET ACTIVATE DataSet1.
USE ALL.
COMPUTE filter_$=(McDonalds = 0 | RedBull = 1 | TacoBell = 1).
VARIABLE LABELS filter_$ 'McDonalds = 0 | RedBull = 1 | TacoBell = 1 (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMATS filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE.

Using char.sub command on multiple variables

I have to select group of cases starting with specific numbers in multiple variables.
I am using this
CHAR.SUBSTR(variable1,1,x) ="y" | CHAR.SUBSTR(variable2,1,x) ="y" .............| CHAR.SUBSTR(variable40,1,x) ="y".
(x is number of character,y is characters I am choosing) the variables are named similar with just the number 1 to 40 being different
it works but problem is there are 40 variables and code is very length.
any elegant way to write it? like variable1 THRU variable 40?
You can loop through the variables and then select. Like this:
do repeat vr=variable1 to variable40.
if CHAR.SUBSTR(vr,1,1)="y" keep_this=1.
end repeat.
select if keep_this=1.
after running the loop, if any of the variables starts with "y" then the line will be marked with 1 in the variable keep_this. Now you can select only cases where keep_this=1.

Using SPSS IF syntax to create a new variable from two categorical variables

I want to create a new variable from two other variables.
The first is SEX (0=male, 1=female; there were no other genders selected by respondents though we had planned for that possibility) whereas the second is RACE9 (0=white, 1=racialized). The new variable is named SEXRACE9.
While the following code produces counts for white males, racialized males, white females and racialized females, the code fails to produce a count for total male or total female.
* Create combined sex and race categorical variable.
IF (sex=0 AND (race9=0 OR race9=1)) sexrace9=1. /*Total males - glitchy.
IF sex=0 AND race9=1 sexrace9=2. /*White males.
IF sex=0 AND race9=0 sexrace9=3. /*Racialized males.
IF (sex=1 AND (race9=0 OR race9=1)) sexrace9=4. /*Total females - glitchy.
IF sex=1 AND race9=1 sexrace9=5. /*White females.
IF sex=1 AND race9=0 sexrace9=6. /*Racialized females.
EXECUTE.
Am I missing something? Alternately, does anyone have a solution for how to insert a count for total males and total females using COMPUTE? Any help is greatly appreciated.
You are missing two key aspects:
Your sexracevariable is intended to define mutually exclusive groups (i.e. - each case will belong to one group, and no case could qualify for more than one group)
SPSS syntax is being run sequentially, line by line, so a syntax line can overwrite previous lines.
More to the point:
IF (sex=0 AND (race9=0 OR race9=1)) sexrace9=1.
is being partially overwritten by
IF sex=0 AND race9=1 sexrace9=2. /*White males.
because white males would qualify for both sexrace=1 and sexrace=2.
, and then by the line
IF sex=0 AND race9=0 sexrace9=3. /*Racialized males.
, because Racialized males qualify for both sexrace=1 and sexrace =3.
So I am guessing that no cases ghave sexrace=1 after running your syntax :)
Exactly the same logic goes for Females.
I am not sure what you want to achieve by your Total Males and Total Femalessyntax lines. You already have the sexvariable to differentiate between males and females.

SPSS: aggregate and count different values

In SPSS i have a variabele with a lot of different values (8 figure number; 00000000). Every row is a person. I want to aggregate this data on postal area and count the number of different values in a postal area. Is there a way?
Result within a postal area should be 1 to N : 1 = every person has the same value, N = every person has a different value
Aggregate in two steps. Assuming your dataset name is data1, with variables var1 (the variable of interest) and postalcode, I would do this:
Create a dataset step1, with one row for each combination of values of postalcode and var1. Also possible by using the command casestovars.
dataset declare step1.
dataset activate data1.
aggregate outf=step1 /break=postalcode var1 /n=n(var1).
Create a dataset result with one row for each postalcode, and a variable n for the number of rows from the previous dataset step1.
dataset declare result.
dataset activate step1.
aggregate outf=result /break=postalcode /n=n(var1).
So, in conclusion: first break by both of the variables, then break only by the variable of postal code. This should do the trick!

Resources