creating a new datasheet and copying values into it in JSL<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />hi
i have a dataset with 50 numbers. I want to calculate the mean of the data set and place the mean value in a different new datasheet "Summary". Again I want to calculate sum of the 50 numbers and place it in the same new datasheet "Summary". Can some one help me how to place these mean and sum values in new datasheet "Summary"?
Thanks,
Re: creating a new datasheet and copying values into it in JSL
Thankyou everyone for helping me in JSL scripting...your skills are highly appreciated!
Re: creating a new datasheet and copying values into it in JSLIf you don't care about some repeats in some samples, there is a SUBSET command under TABLES that produce random samples:
Subset( Sample Size( 10 ) )
that should produce the random 10 for each iteration.
As for the summary for each group, you can use STACK COMMAND to gather all data while preserving column (sampling group) names, then apply either tabulate or summary by sample group.
i'd like too give all that in a script but my scripting is very slow. may be later..
MS, excellent clean scripting, as always.
Barry
Re: creating a new datasheet and copying values into it in JSLSorry, I inverted the fraction. It should read
fraction = k / N Rows( dt );
This fraction (a number between 0 and 1) is calculated only because the random selection requires a fraction argument.
Here is a version that also puts each subsample in the output table. After the mean and SD columns you should see ten columns with the ten randomly picked data for each iteration.
dt = Data Table( "Data" );
k = 10; //Set sample size
n = 100; //Set number of iterations
fraction = k / N Rows( dt );
m = J( n, 2 + k ); //Initiate a matrix for holding means and SDs
//Loop: make random subset n times
For( i = 1, i <= n, i++,
dt << select randomly( fraction );
m[i, 1] = Mean( dt:Data[dt << get selected rows] );
m[i, 2] = Std Dev( dt:Data[dt << get selected rows] );
m[i, 3 :: 2+ k] = transpose(dt:Data[dt << get selected rows]);
);
//Move data into new table
dt2 = As Table( m );
dt2 << set name( "Summary Data" );
Column( dt2, 1 ) << set name( "Mean" );
Column( dt2, 2 ) << set name( "StdDev" );
Re: creating a new datasheet and copying values into it in JSL
And each time if I want to see the subset of 10 values from which mean and STD Dev. is calculated, can I have that option?
Re: creating a new datasheet and copying values into it in JSLyes. I got the final sheet, but what does the fraction line do? Does that create a formula for the random sample?
Re: creating a new datasheet and copying values into it in JSLI used that file when writing the script. I just pasted the values in the text file into a new JMP table (you ca also open it from within JMP), renamed the file from "untutled" to "Data" and gave the column the name "Data". Try again!
Re: creating a new datasheet and copying values into it in JSLThe line dt2 = As Table( m ); creates the table. What does your log say?
The script here assumes you have a Table called "Data" and a column with your data also with name "Data".
Re: creating a new datasheet and copying values into it in JSLcan you please let me understand with this txt file. Sorry, but iam not much used to JSL,
Re: creating a new datasheet and copying values into it in JSLsomehow I couldnot see the final table with means and standard deviations..where is it created?
Re: creating a new datasheet and copying values into it in JSLHere is one way. The loop incrementally fills a matrix that is converted into a datatable at the end.
dt = Data Table( "Data" );
k=10; //Set sample size
n = 100; //Set number of iterations
fraction = 1 - k / N Rows( dt );
m = J( n, 2 ); //Initiate a matrix for holding means and SDs
//Loop: make random subset n times
For( i = 1, i <= n, i++,
dt << select randomly( fraction );
m[i, 1] = Mean( dt:Data[dt << get selected rows] );
m[i, 2] = Std Dev( dt:Data[dt << get selected rows] );
);
//Move data into new table
dt2 = As Table( m );
dt2 << set name( "Summary Data" );
Column( dt2, 1 ) << set name( "Mean" );
Column( dt2, 2 ) << set name( "StdDev" );
Re: creating a new datasheet and copying values into it in JSLyes, I want to know how to create samples of 10 and if I were to create these samples of 10 multiple times(say more than 100), do I need to write it in a loop? How do I use loop here to create samples of 10 multiple times?
Re: creating a new datasheet and copying values into it in JSLI was looking at your second post - it is the same idea but i would create a new table collecting the samples of 10 into columns then produce a summary just once. if no one else answers this i will answer this later today after I take care of people who pay my bills (an expectant lot )
Re: creating a new datasheet and copying values into it in JSLActually, I wanted to do this:-i posted this question in the forum too..
I have a data set with 1000 variables, continous numbers. I want to take a random subset from the dataset and calculate the mean and standard deviation of the subset and place in a separate excel file "B". I want to repeat this process -process of taking the subset of size 10 from the original dataset with 1000 variables and calculate mean and standard deviation and place in the same excel file "B". The final excel sheet shll contain all the means and standard deviations .
Iam not very sure if the script that you have given me can help in creating a new sheet in the above question..
i attached my sample data sheet ..
Re: creating a new datasheet and copying values into it in JSLDo you really mean to do this in JSL - i.e. to create a script that you can run to produce the summary? If you want to do this just one time interactively? I will answer both:
Interactively:
Create your data table - in this case i call it RawData,
Click Table >> Tabulate
Click Data and then Mean and drag it to the output area
Click Sum and drag it to the output area
Click on red triangle of the report >> Make into Data Table, or just use the report directly (Cut and Paste)
Using JSL
After creating the above using Make Into Data Table, name the table (Summary Report is used here)
Click on the red triangle >> Copy Script
Create a new script (File>>New>>Script)
Paste your newly copied script into the new script window
Close your previous summary report
Run the script you just created
The summary report should pop up
An example i made with random data:
Script:
New Table( "Summary Report",
Add Rows( 1 ),
New Script(
"Source",
(Data Table( "RawData" ) << Tabulate(
Add Table(
Column Table( Statistics( Mean, Sum ), Analysis Columns( :Data ) )
)
)) << Make Into Data Table
),
New Column( "Mean(Data)",
Numeric,
Continuous,
Format( "Best", 5 ),
Set Values( [171.936] )
),
New Column( "Sum(Data)",
Numeric,
Continuous,
Format( "Best", 5 ),
Set Values( [8596.8] )
)
)
Message me if you want my example files.
Barry