Comparing values between lines within a group - spss

I'm looking to create a column denoting if a survey respondent has changed locations from Wave 6 to Wave 7. I do not care about previous waves (although they are there in the data).
So the logic I want is: If the email from Wave 6= the email from Wave 7 and location from 6 <> location from 7 then 1. So I'm only concerned about respondents that show up in both waves 6 and 7.
Here is an example of the output that I would want: (I want the 1 to appear both on Wave 6 and Wave 7, denoting the change for both waves).
I'm unsure how to logically write this in SPSS. Any tips would be appreciated. Thanks!

Many ways to do this, so here's one that should work assuming there is only one occurrence of every wave X Email_A combination:
sort cases by Email_A wave.
compute changeLocation=
(Email_A=lag(Email_A) and wave=7 and lag(wave)=6 and location<>lag(location)).
at this point you have the 1 in every relevant row of wave=7. Now to get this to the wave=6 rows there are also a few ways but here's a fun one:
sort cases by Email_A wave (d).
if Email_A=lag(Email_A) and wave=6 and lag(changeLocation)=1 changeLocation=1.

Related

Sound Wave Peak Detection (Cricket Chirping)

I am looking for a way to code or find a program that can record the chirps of crickets either live or through a prerecorded audio file (large ~24 hours) for a lab experiment.
I'm not too sure how to approach this as I'm a web developer, but I have experience with JS and python, along with libraries. My initial idea was to use Matplotlib to produce an audio visualizer, and then count each time a certain range of db is reached which matches the db of a cricket chirp, but I have no idea how to approach it.
I have successfully visualized the chirps on a online spectrum analyzer (Spectrum Visualizer of Audio Chirps), and can see it clearly, however I don't know how I can use code to count each "chirp" and record it along with the date and time for each chirp in a table of values / dataset of some sort.
Any guidance or help would be greatly appreciated!
Really naive solution: For every unit of time (column of pixels in the spectrogram), you can calculate the sum of all the values in a column. For example, if all the pixels in a column are black, the sum for that column will be 0, if some of them are colored, the sum will be >0.
Then loop over the sums: if at a certain step you go from 0 to > 0, and then after a while you go back to 0, you've hit a peak.
If the output is too "noisy", you can use a small threshold value instead of 0. Tweak it until results seem OK. This works well when the input background noise is pretty much the same all the way through, but if it's skewed up and down during the whole recording, you need something more complicated (for example, the threshold constantly changes with the average of the last n sums)
Or you can Google "peak detection algorithm" and implement one of them. Or you can Google "peak detection library" in your favourite language and use one of them.

SPSS: Multiple data lines for individual cases

My dataset looks like this:
ID Time Date_____v1 v2 v3 v4
1 2300 21/01/2002 1 996 5 300
1 0200 22/01/2002 3 1000 6 100
1 0400 22/01/2002 5 930 3 100
1 0700 22/01/2002 1 945 4 200
I have 50+ cases and 15+ variables in both categorical and measurement form (although SPSS will not allow me to set it as Ordinal and Scale I only have the options of Nominal and Ordinal?).
I am looking for trends and cannot find a way to get SPSS to recognise each case as whole rather than individual rows. I have used a pivot table in excel which gives me the means for each variable but I am aware that this can skew the result as it removes extreme readings (I need these ideally).
I have searched this query online multiple times but I have come up blank so far, any suggestions would be gratefully received!
I'm not sure I understand. If you are saying that each case has multiple records (that is multiple lines of data) - which is what it looks like in your example - then either
1) Your DATA LIST command needs to change to add RECORDS= (see the Help for the DATA LIST command); or
2) You will have to use CASESTOVARS (C2V) to put all the variables for a case in the same row of the Data Editor.
I may not be understanding, though.

NetLogo Histogram - Distribution of visits

I've a simple problem.
In my code there are some patches that contain food. I computed the # of visits for each one of these "resources". Now I want to put in a histogram the # of visits for each one of these "resource-patches" .
If I write in the GUI:
histogram [visits] of resource-patches
It plots me something strange.
This is because, usually, you put the "x" values in the brackets [ ] of the patches-own attribute. Instead, I want that
-in the "x-axis" there are the labels (for example) of the resource-patches (or their amount of food) whereas
-in "y-axis" I want the #of visits for each one of the resource-patches.
I'm struggling since yesterday but I can't find a solution.
Thank you in advance guys!
A histogram only takes in the values for the x-axis. The y-axis will always be the number of occurrences of x in the list provided. For you, it'll plot the frequency of each of yours visits.
If your visits list is [1 1 3 5 2 3 4 5]
You'll see a histogram of
x, y
1->2
2->1
3->1
4->1
5->2
I think you may want to look at another plotting tool if this is not what you want.

ELKI OPTICS pre-computed distance matrix

I can't seem to get this algorithm to work on my dataset, so I took a very small subset of my data and tried to get it to work, but that didn't work either.
I want to input a precomputed distance matrix into ELKI, and then have it find the reachability distance list of my points, but I get reachability distances of 0 for all my points.
ID=1 reachdist=Infinity predecessor=1
ID=2 reachdist=0.0 predecessor=1
ID=4 reachdist=0.0 predecessor=1
ID=3 reachdist=0.0 predecessor=1
My ELKI arguments were as follows:
Running: -dbc DBIDRangeDatabaseConnection -idgen.start 1 -idgen.count 4 -algorithm clustering.optics.OPTICSList -algorithm.distancefunction external.FileBasedDoubleDistanceFunction -distance.matrix /Users/jperrie/Documents/testfile.txt -optics.epsilon 1.0 -optics.minpts 2 -resulthandler ResultWriter -out /Applications/elki-0.7.0/elkioutputtest
I use the DBIDRangeDatabaseConnection instead of an input file to create indices 1 through 4 and pass in a distance matrix with the following format, where there are 2 indices and a distance on each line.
1 2 0.0895585119724274
1 3 0.19458931684494
2 3 0.196315720677376
1 4 0.137940123677254
2 4 0.135852232575417
3 4 0.141511023044586
Any pointers to where I'm going wrong would be appreciated.
When I change your distance matrix to start counting at 0, then it appears to work:
ID=0 reachdist=Infinity predecessor=-2147483648
ID=1 reachdist=0.0895585119724274 predecessor=-2147483648
ID=3 reachdist=0.135852232575417 predecessor=1
ID=2 reachdist=0.141511023044586 predecessor=3
Maybe you should file a bug report - to me, this appears to be a bug. Also, predecessor=-2147483648 should probably be predecessor=None or something like that.
This is due to a recent change, that may not yet be correctly presented in the documentation.
When you do multiple invocations in the MiniGUI, ELKI will assign fresh object DBIDs. So if you have a data set with 100 objects, the first run would use 0-99, the second 100-199 the third 200-299 etc. - this can be desired (if you think of longer running processes, you want object IDs to be unique), but it can also be surprising behavior.
However, this makes precomputed distance matrixes really hard to use; in particular with real data. Therefore, these classes were changed to use offsets. So the format of the distance matrix now is
DBIDoffset1 DBIDoffset2 distance
where offset 0 = start + 0 is the first object.
When I'm back in the office (and do not forget), I will 1. update the documentation to reflect this, provide 2. an offset parameter so that you can continue counting starting at 1, 3. make the default distance "NaN" or "infinity", and 4. add a sanity check that warns if you have 100 objects, but distances are given for objects 1-100 instead of 0-99.

How do I show only an one digit in the 4 digit segment on a Basys2 board?

When I used to output an one digit number in the Basys2 board, all the 4 digits glowed. eg:- When I wanted 2, it showed 2222. I want only the right most digit to work.
To achieve this, I made a ground port connected to three out puts through 3 NOT gates on the schematic file. Next I LOC that three outputs to the 3 anodes, AN1, AN2, AN3 of the board in the ucf file.
But, is there any proper way to do this?
You have to implement a time multiplexer.
That takes your four input digits and displays only one at a time by selecting the proper AN* signal. You should multiplex the digits > 100 Hz and < 1 kHz.

Resources