Reputation: 10626
Is it possible to print out the mathematical formula of the model in R. For example,
library(usl)
data(raytracer)
usl.model <- usl(throughput ~ processors, data = raytracer)
I would like to be able to look at this model's (usl.model) formula. Any ideas wheter is this doable or not?
Upvotes: 0
Views: 582
Reputation: 791
The 'usl' documentation says:
The Universal Scalability Law can be expressed with following
formula. ‘C(N)’ predicts the relative capacity of the system for a
given load ‘N’:
C(N) = N / (1 + sigma * (N - 1) + kappa * N * (N - 1))
I'm not sure how to interpret your question, but would it work to take
the sigma
and kappa
coefficients from summary(usl.model)
and
plug them into this equation?
Update: For the raytracer
example, it looks like N
represents the
number of processors and C(N)
the throughput:
N=raytracer$processors;
attach(as.list(usl.model@coefficients))
[email protected]
data.frame(raytracer, pred=F* N / (1 + sigma * (N - 1) + kappa * N * (N - 1)))
This produces:
processors throughput pred
1 1 20 20.00000
2 4 78 69.55746
3 8 130 118.48067
4 12 170 154.75037
5 16 190 182.70168
6 20 200 204.89242
7 24 210 222.92923
8 28 230 237.87214
9 32 260 250.44877
10 48 280 285.56580
11 64 310 306.91823
I'm not sure how sigma and kappa are calculated. The documentation
says that the default
method uses "a transformation into a 2nd
degree polynom" (citing Gunther) but if the model frame lacks a
predictor with value 1 then it seems to fall back to optimizing the
coefficients (scale factor, sigma and kappa) to minimize the sum of
squared differences between the actual and predicted response variable
(the last two columns above).
Upvotes: 1
Reputation: 7443
It is in the call
slot of the model. You can access it with:
> usl.model@call
usl(formula = throughput ~ processors, data = raytracer)
A more compact option, eg for display purpose, is:
> print(as.formula(usl.model@call), showEnv=FALSE)
throughput ~ processors
More generally, on complex objects/lists/etc., str()
is a nice entry point on the structure.
> str(usl.model)
Formal class 'USL' [package "usl"] with 15 slots
..@ frame :'data.frame': 11 obs. of 2 variables:
.. ..$ throughput: num [1:11] 20 78 130 170 190 200 210 230 260 280 ...
.. ..$ processors: num [1:11] 1 4 8 12 16 20 24 28 32 48 ...
.. ..- attr(*, "terms")=Classes 'terms', 'formula' length 3 throughput ~ processors
[.../...]
..@ call : language usl(formula = throughput ~ processors, data = raytracer)
..@ regr : chr "processors"
..@ resp : chr "throughput"
You can also add @
(or $
) to the object name (eg usl.model@
) and then press <tab>
.
Upvotes: 1