Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Least squares mean in BE #33

Open
skyee1 opened this issue Sep 29, 2021 · 5 comments
Open

Least squares mean in BE #33

skyee1 opened this issue Sep 29, 2021 · 5 comments

Comments

@skyee1
Copy link

skyee1 commented Sep 29, 2021

How to use API to obtain the least squares mean of rbe results

@PharmCat
Copy link
Owner

Hi!
You can see Metida.jl. You can find it more general.

In ReplicateBE you can get model coefficients with coef or you can get an estimate for your contrast matrix with estimate

Can you provide SAS code for your task?

@skyee1
Copy link
Author

skyee1 commented Sep 30, 2021

Hi!
Thank you for your reply!
Follow is my SAS code for my task:
sas proc mixed data=be; class seq trt per subject ; model lcmax=seq trt per/ddfm=satterth; random trt/sub=subject type=fa0(2); repeated /group=trt sub=subject; lsmeans trt ; ods output Estimates=est; ods output LsMeans=lsm; ods output Tests3=anova; ods output CovParms=res(rename=(estimate=var)); run;

@skyee1 skyee1 closed this as completed Sep 30, 2021
@skyee1 skyee1 reopened this Sep 30, 2021
@PharmCat
Copy link
Owner

PharmCat commented Sep 30, 2021

proc mixed ...

Actually, I understand what you want. Your code leads to some warnings with output. I make a few changes (check the level of reference ):

proc mixed data=be; 
class seq trt(ref="R") per subject; 
model lcmax=seq trt per/ddfm=satterth solution; 
random trt/sub=subject type=fa0(2); 
repeated /group=trt sub=subject; 
lsmeans trt ; 
ESTIMATE 'diff' trt 1 -1/CL ALPHA=0.1;
ods output Estimates=est; 
ods output LsMeans=lsm; 
ods output Tests3=anova; 
ods output CovParms=res(rename=(estimate=var)); 
run;

So for LsMeans in ReplicateBE at first you should make L matrix (1xp), where p - length of fixed effect vector coef
If you have 2 sequences, 4 periods, 2 treatments (your model is 1 + seq + per + trt) you will have 6 coefficients. and for T and R treatment you will have these matrices:

#1 
[1 0.5 0.25 0.25 0.25 0]
#2 
[1 0.5 0.25 0.25 0.25 1]

then you can get an estimate:

estimate(rbe, [1 0.5 0.25 0.25 0.25 0]; name = "Estimate 1", alpha = 0.05)

There is no automatic creation of L-matrix by the factor in ReplicateBE. But this can be done easily:

Set 1 for Intercept coefficient, set 1 for one level of the factor of interest (or 0 for base level). For other sets 1/n where n - number of levels in a factor. For the example above: 1st - intercept, 2nd - 1/2 (2 sequences), 3-5 - 1/4 (4 periods), 6 - 1 for T 0 for R.

@skyee1
Copy link
Author

skyee1 commented Jan 5, 2022

Thanks for your reply!

This package is very useful for my research. I also recommended it to my colleagues. this tutorial has perfectly solved my problem for your reply.

I have starred this depot. However, I found that it takes a long time to run data for the first time (sample size is 27). , and it may take 80 seconds. But the second run will be very fast.

I would like to know what caused this. I use this package in R through JuliaConnectoR. In fact, it also has this problem when running in julia (it takes a long time).

Hope to get your reply.

My computer configuration is as follows.

  • Session info --------------------------------------------------------
    setting value
    version R version 4.0.5 (2021-03-31)
    os Windows 10 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate Chinese (Simplified)_China.936
    ctype Chinese (Simplified)_China.936
    tz Asia/Taipei
    date 2022-01-05

@PharmCat
Copy link
Owner

PharmCat commented Jan 6, 2022

Hi! Glad if this repo helps you! "First time run" is a known feature (problem) of Julia - this time used for compilation. Second run - is real work time. Also other packages can take time for compilation. ReplicateBE using ForwardDiff for REML gradient and hessian - it add little more compile time. In future development ReplicateBE will use Metida for fitting, it can help to make better fitting and validation.
Also you can read this: https://discourse.julialang.org/t/time-to-first-plot-clarification/58534
And if you use julia image with some precompiled modules https://docs.julialang.org/en/v1/devdocs/sysimg/

One more question. Why are you using Julia under R? Is any specific package that is not present in Julia?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants