Professional Documents
Culture Documents
BT-588221-Assignment # 2 1569
BT-588221-Assignment # 2 1569
02
ASSIGNMENT No.
Submission Date
Due Date
Signature*
Name: M. Hashim Javed Roll: BT-588221
Q1. (a). What are macros and what are there types.
Macros
Minitab macros are collections of Minitab code that allow the user to implement in a single command
procedures and techniques which would otherwise require many separate Minitab commands to be
entered. A macro has a name which is the means by which the user invokes the macro.
Types of macros
Three types of macros have been developed in Minitab to perform various repetitive tasks easily and
effectively:
Global Macros
Allow you to analyze and manipulate data in the active worksheet. However, the identity of any
columns, constants, and matrices that are to be accessed must be specified within the macro; therefore,
the worksheet must be configured the same way each time the macro is run.
ENDMACRO
i. Variables
A variable is an alias that can refer to some piece of data: a number, text string, column,
constant, or matrix. For example, a variable named "Test1" could represent any of the following:
a column of test scores, a constant that is the mean of the test scores, or a text string that is the
name of the test.
ii. Arguments
Arguments are variables that are passed into and out of a macro when it is invoked. The
variables are listed on the main command line and subcommand lines of the macro. If you pass
a global worksheet variable (a column, constant, or matrix) to a macro and the macro changes
the value of that variable, the global worksheet variable will contain that changed value after
the macro executes. An argument can be a variable which represents:
• a stored column, constant, or matrix from a global worksheet: 'Sales', C1, K2,
or M1
• a number such as 2.3
iii. Variables
Local macros can also have subcommands that can modify the behavior of the macro –
just as subcommands in interactive Minitab can change the behavior of a command.
Subcommands can have their own arguments. You can also choose to include or not include the
subcommand when invoking the local macro.
For example, the scatter plot macro described above could be made more flexible by
including a subcommand that lets you decide at what level the confidence bands should be
drawn
MCONSTANT N T1 T2 XBAR
MCOLUMN X XSORT XTRIM
(4) #
# first we calculate the trimming points T1 and T2
LET N = COUNT(X)
LET T1 = ROUND(N*0.05)
LET T2 = N-T1+1
# next we check for the case when T1 = 0 and nothing is trimmed
IF T1 = 0
LET XTRIM = X
# otherwise, we sort X, trim the ends and calculate the mean
ELSE
LET XSORT =SORT(X)
COPY XSORT XTRIM;
OMIT 1:T1 T2:N.
ENDIF
LET XBAR = MEAN(XTRIM)
(5) ENDMACRO
Key
Here is what each line in the macro means:
1. MACRO marks the beginning of a local macro.
2. Template. Says to invoke this macro with two arguments: argument 1 is the column of data to be
trimmed, and argument 2 is the constant where the trimmed mean is to be stored
3. Declaration statements:
• MCONSTANT declares four constants (N, T1, T2, and XBAR) to be used as variables by the local
macro. One of these constants, XBAR, is an argument which corresponds to the constant that is
passed into the macro when the user invokes the macro.
• MCOLUMN declares three columns (X, XSORT, and XTRIM) to be used as variables by the local
macro. One of these columns, X, is an argument which corresponds to the column that is passed
into the macro when the user invokes the macro.
4. Body of the macro.
5. ENDMACRO marks the end of the macro.
If you have Execs that were written using previous releases of Minitab, you can continue to use them
with no change, unless, of course, the Execs use deprecated commands.
MACRO
diethrow
mcolumn a
mconstant n x y z p1 p2
let n = count(a)
let x = 0
let y = 0
do x = 1 : n
if MOD(a(x),2)=0
let y = y + 1
endif
enddo
let z=(y/n)*100
ENDMACRO
MACRO
mdev a
mcolumn a b c
mconstant k1 k2
Let k1 = MEAN(a)
Let b = a - K1
Let c = ABSO(b)
Let k2 = MEAN(c)
print k2
endmacrO
MACRO
systsam a
mcolumn a b
mconstant n np
let Np = count(a)
let n = 50
ENDMACRO
MACRO
percentile a sc
mcolumn a b
mconstant sc n x y z
let n=count(a)
let b=sort(a)
let y=0
let x=0
do x=1:n
if b(x)<=sc
let y=y+1
endif
enddo
let z=(y/n)*100
print z
ENDMACRO
2. SPSS is generally stronger in statistical analysis, especially in some specific area, such as
ANOVA-related procedures. The add-on modules give SPSS further flexibility and
potentials to develop its capacities. However, for cutting-edge statistical analysis, SPSS is
stronger than Minitab. So SPSS is most suitable to you if your work involves large dataset,
frequent data management, and intermediate/partially-advanced statistical analysis.
3. SPSS Statistics is loaded with powerful analytic techniques and time-saving features to
help you quickly and easily find new insights in your data, so you can make more accurate
predictions and achieve better outcomes for your organization.
4. View interactive SPSS Statistics output on smart devices (smartphones and tablets) and
Generate presentation-ready output quickly and easily
6. SPSS Advanced Statistics offers generalized linear mixed models (GLMM), general linear
models (GLM), mixed models procedures, generalized linear models (GENLIN) and
generalized estimating equations (GEE) procedures.
Commands in R
P-value and t-test
t.test({x1},{x2})
Commands in Minitab
P-value and t-test
MTB > Onet '{testing-data-variable}';
SUBC> Test {testing-against-mean-value};
SUBC> Confidence 95.0;
SUBC> Alternative 0.
R - Functions
A function is a set of statements organized together to perform a specific task. R has a
large number of in-built functions and the user can create their own functions.
In R, a function is an object so the R interpreter is able to pass control to the function,
along with arguments that may be necessary for the function to accomplish the actions.
The function in turn performs its task and returns control to the interpreter as well as any
result which may be stored in other objects.
Function Definition
An R function is created by using the keyword function. The basic syntax of an R
function definition is as follows −
function_name <- function(arg_1, arg_2, ...) {
Function body
}
Function Components
The different parts of a function are −
• Function Name − This is the actual name of the function. It is stored in R environment as an
object with this name.
• Arguments − An argument is a placeholder. When a function is invoked, you pass a value to
the argument. Arguments are optional; that is, a function may contain no arguments. Also
arguments can have default values.
• Function Body − The function body contains a collection of statements that defines what the
function does.
• Return Value − The return value of a function is the last expression in the function body to be
evaluated.
R has many in-built functions which can be directly called in the program without
defining them first. We can also create and use our own functions referred as user
defined functions.
Built-in Function
Simple examples of in-built functions
are seq(), mean(), max(), sum(x) and paste(...) etc. They are directly called by user
written programs. You can refer most widely used R functions.
# Create a sequence of numbers from 32 to 44.
print(seq(32,44))
Calling a Function
Live Demo
R Arithmetic Operators
These operators are used to carry out mathematical operations like addition and
multiplication. Here is a list of arithmetic operators available in R.
Operator Description
+ Addition
– Subtraction
* Multiplication
/ Division
^ Exponent
Q5. (b) Create a function in R, that will calculate the number of divisors of any integer given
by the user. It also displays all the divisors.
divisors(15)
The user will pass the integer in the function named divisors(x), and the function will print the divisors
and return the number of divisors for that integer.
comb()
The user will be prompted to enter the values for r and n in nPr, and then these values will be used in the
calculation of nPr and the function will print the answer as number of combinations.
We will pass the vector as ‘x’ and the integer as ‘y’ to check in the function match(x,y) and the function
will return the number of times integer y appears in the given vector.
1 2 3 4
1 2 3
1 2
flag()
Upon calling the function flag() the required output will be produced.
fizzbuzz()