Learn R Programming

DoE.base (version 0.5)

add.response: Function to add response values to an experimental design

Description

This function allows to add numeric response variables to an experimental plan of class design. The responses are added both to the data frame and to its desnum attribute; the response.names element of the design.info attribute is updated - the function is still experimental.

Usage

add.response(design, response, rdapath=NULL, replace = FALSE, 
    InDec=options("OutDec")[[1]], ...)

Arguments

design
a character string that gives the name of a class design object, to which responses are to be added
response
EITHER a numeric vector, numeric matrix or data frame with at least one numeric variable (the treatment of these is explained in the details section) OR a character string indicating a csv file that contai
rdapath
a character string indicating the path to a stored rda file that contains the design
replace
logical: TRUE implies that existing variables are overwritten in design; cf. also the details section
InDec
decimal separator in the external csv file; defaults to the OutDec option (viewable under options("OutDec"), and also governs whether the csv-file is read with
...
further arguments; currently not used

Value

  • The value is a modified version of the argument object design, which remains an object of class design with the following modifications:
  • Response columns are added to the data frame
  • the same response columns are added to the desnum attribute
  • the response.names element of the design.info attribute is added or modified

Details

If response is a data frame or a matrix, responses are assumed to be all the numeric variables that are neither factor names in design (i.e. names of the factor.names element of the design.info attribute nor column names of the run.order attribute. If design already contains columns for the response(s), these are per default overwritten if there are NA entries only in all such columns, but not otherwise. The idea behind this function is as follows: After using export.design for storing an R work space with the design object and either a csv or html file externally, Excel or some other external software is used to type in experimental information. The thus-obtained data sheet is saved as a csv-file and imported into R again (name provided in argument response, and the design object with all attached information is linked to the typed in response values using function add.response. Alternatively, it is possible to simply type in experimental results in R, both using the R commander plugin (RcmdrPlugin.DoE) or simply function fix. Copy-pasting into R from Excel is per default NOT possible, which has been the reason for programming this routine.

References

~put references to the literature/web site here ~

See Also

See also export.design

Examples

Run this code
plan <- fac.design(nlevels=c(2,3,2,4))
       result <- rnorm(2*3*2*4)
       add.response(plan,response=result)
       
   export.design(path="c:/projectA/experiments",plan)
       ## open exported file c:/projectA/experiments/plan.html
       ##        with Excel
       ## carry out the experiment, input data in Excel or elsewhere
       ##        store as csv file with the same name (or a different one, just use 
       ##        the correct storage name later in R), after deleting 
       ##        the legend portion to the right of the data area
       ##        (alternatively, input data by typing them in in R (function fix or R-commander)
       add.response(design="plan",response="c:/projectA/experiments/plan.csv",
                 rdapath="c:/projectA/experiments/plan.rda")
       ## plan is the name of the design in the workspace stored in rdapath
       ## assuming only responses were typed in
       ## should work on your computer regardless of system, 
       ##         if you adapt the path names accordingly

Run the code above in your browser using DataLab