Proc model solve for X preserving sample size

Reply
Super Contributor
Posts: 303

Proc model solve for X preserving sample size

data CP;

input t s uu;

cards;

1  2  3

0 2   3

0  3  3

1  2  2

1  4  5

;

proc model data=CP ;

where t=1;

eq.sn=(UU- exp(s-tc)**2;

solve tc/out=myso;

run;

The data set myso will be like this:

1

PREDICT

SIMULATE

0

  1. 1.48371

3

2

2

PREDICT

SIMULATE

0

-7.60045

2

2

3

PREDICT

SIMULATE

0

-7.60045

5

4

However I want a data with all the observations including the  the cases where t=0.

I tried this but it it was not good:

proc model data=CP ;

tc=s;

where t=1;

eq.sn=(UU- exp(s-tc)**2;

solve tc/out=myso;

run;

Please help??

Super User
Posts: 11,343

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

Remove the Where t=1; statement perhaps?

Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

It does not work

Respected Advisor
Posts: 4,930

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

How about

data CP;

input t s uu;

cards;

1  2  3

0  2  3

0  3  3

1  2  2

1  4  5

;

proc model data=CP plots=none;

UU = exp(s-tc);

fit UU parms=(tc) / out=myso outall;

weight t;

run;

PG

PG
Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

Thanks PGStats, I am running this withing a simulation. THis is the code:

proc model data=CP_est_&u plots=none;

UU=-exp(-(k-alpha1*timec)**2/2*Sigma**2))*(1-SURVIVAL1)+(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

fit UU parms=(timec) / out=myso_&u outall;

weight timec;

run;

However, no data is created, instead I have the following error:

WARNING: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.

alpha0=2.57016 alpha1=2.23407 alpha2=4.01224 sigma=0.15054 beta=0.60420 lambda=1.830 Replicate=1

X=1 time=0.0093138115 censored=0 obs=1 y=6.8196847642 NumberHits=2 survival=0.7772239588

ht_Sum=0.1105307015 SURVIVAL1=0.7772239588 pi=3.1415926536 k=-23.39127707 CD=-0.134368884

M=0.9482803906 N=. P=. Z=-0.1062101 _ERROR_=1 _N_=36

233   plots=none;

233! UU=-exp(-(k-alpha1*timec)**2/2*Sigma**2))*(1-SURVIVAL1)+(exp(-(k-alpha1*timec)**2/2*Sigma**2)

Respected Advisor
Posts: 4,930

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

You cannot estimate timec and use it as a weight. Also, for testing, replace macro variable &u invocation with a fixed value. - PG

PG
Respected Advisor
Posts: 4,930

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

Looking at your equation, I suspect that the expression 2*Sigma**2 should be within parentheses at both places where it appears. - PG

PG
Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

Hello ,

I made some corrections:

proc model data=CP_est_&u plots=none;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)+(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

fit UU parms=(timec) / out=myso_&u outall;

weight censored;

run;

However, it didnt solve for timec. This is the output. It is not solving for timec,

Obs_ESTYPE__TYPE__WEIGHT_censoredUUkalpha1sigmaSURVIVAL1
1OLSACTUAL000.51.08041.4570.233730.99018
2OLSPREDICT00-0.072631.08041.4570.233730.99018
3OLSRESIDUAL000.572631.08041.4570.233730.99018
4OLSACTUAL11-0.01835-0.50531.4570.233730.9851
5OLSPREDICT11-0.09713-0.50531.4570.233730.9851
6OLSRESIDUAL110.07878-0.50531.4570.233730.9851
7OLSACTUAL11-0.009154.81461.4570.233730.98257
8OLSPREDICT11-0.003034.81461.4570.233730.98257
9OLSRESIDUAL11-0.006124.81461.4570.233730.98257
Respected Advisor
Posts: 4,930

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

Now I think I understand. You simply want to find the value of timec that solves the equation for each observation of your dataset when t=1. This should be close to what you want:

data test;
input obs t UU k alpha1 sigma SURVIVAL1 ht_sum;
datalines;
1 1 -0.01835 -0.5053 1.457 0.23373 0.9851 0.01
2 0  0.01835 -0.5053 1.457 0.23373 0.9851 0.01
;

proc model plots=none noprint;
id obs t;
UU = exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1) * (alpha1*(k - alpha1*timec) - 1) - ht_sum;
solve timec satisfy=(UU) / data=test(where=(t)) out=testOut;
run;

proc sql;
create table testSol as
select * from test natural left join testOut
order by obs;
select * from testsol;
quit;

You could also use the SOLVE function of proc fcmp to do this.

PG

PG
Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

Happy New year. Thanks for the great help. Your code runs well. However, when I try to transfer it to simulation in which I am trying to run, it did not work. This is what I got:

proc model plots=CP_est_&u noprint;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

solve timec satisfy=(UU) / data=myso_&u(where=(censored)) out=testOut_&u;

run;

proc sql;

create table testSol_&u as

select * from myso_&u natural left join testOut_&u

order by time;

select * from testsol_&u;

quit;

I am testing a model and can only do it within a simulation set up. I macro runs well up till the steps above. Any help how to make it work within simulation

Thanks

Folefac

Respected Advisor
Posts: 4,930

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

What messages did you get? To get your code to work, you will at least need to replace plots=CP_est_&u by plots=none, change data=myso_&u to data=CP_est_&u, put the second instance of 2*Sigma**2 within parentheses and add statement

ID time;

within your proc model.

PG

PG
Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

Hi This is what I got thanks to your corrections:

It does not run.

proc model plots=none noprint;

id time censored;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

solve timec satisfy=(UU) / data=CP_est_&u (where=(censored)) out=testOut_&u;

run;

proc sql;

create table testSol_&u as

select * from CP_est_&u natural left join testOut_&u

order by time;

select * from testsol_&u;

quit;

NOTE: There were 100 observations read from the data set WORK.CPH_EST_11.

NOTE: The data set WORK.CP_EST_11 has 100 observations and 24 variables.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.01 seconds

ERROR: The solution did not converge for observation 1 after 4 NEWTON iterations using the

       convergence criterion CONVERGE=1E-8.

NOTE: The data set WORK.TESTOUT_11 has 1 observations and 12 variables.

NOTE: PROCEDURE MODEL used (Total process time):

      real time           0.10 seconds

      cpu time            0.03 seconds

NOTE: Table WORK.TESTSOL_11 created, with 100 rows and 28 columns.

NOTE: PROCEDURE SQL used (Total process time):

      real time           0.13 seconds

      cpu time            0.14 seconds

NOTE: Variable timeC is uninitialized.

NOTE: There were 100 observations read from the data set WORK.CPH_EST_11.

NOTE: The data set WORK.IMPUTE_TT_11 has 100 observations and 24 variables.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

THIS IS  HOW THE DATA IS LIKE: IT DIDNT WORK the way I wanted, timec is all set to missing

timecensoredUUkalpha1SigmaSURVIVAL1ht_sum_TYPE__MODE__ERRORS_timec
3.59E-0500.5-9.8981.050820.185740.9802-0.0494..
3.59E-0510.5-9.8981.050820.185740.9802-0.0494..
5.08E-0500.50.526331.050820.185740.95065-0.0494..
5.08E-0500.50.526331.050820.185740.95065-0.0494..
5.08E-0500.50.526331.050820.185740.95065-0.0494..
0.00027100.5-5.35211.050820.185740.9407-0.0494..
0.00054800.5-4.96861.050820.185740.9209-0.0494..
0.00054800.5-4.96861.050820.185740.9209-0.0494..
0.00057610.56.333291.050820.185740.90109-0.0494..
0.00057610.56.333291.050820.185740.90109-0.0494..
Respected Advisor
Posts: 4,930

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

Proc Model could not find the solution, possibly because of the missing parentheses (added in red) in your equation

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/(2*Sigma**2)))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

There is also the possibility that some parameter combinations do not have a solution for timec.

PG

PG
Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

THis works:

data test;

input obs t UU k alpha1 sigma SURVIVAL1 ht_sum time ;

datalines;

1 1  0.01835  0.5053 1.457 0.23373 0.9851 0.01  .000520410

2 0  0.01835  0.2053 1.457 0.23373 0.9851 0.01  .000690482

3 1  0.03835  0.3053 1.457 0.23373 0.9851 0.01  .000690482

4 0  0.02835  0.1053 1.457 0.23373 0.9851 0.01  .001781026

;

proc model plots=none noprint;

id time t;

UU=-exp(-(k-alpha1*timec)**2/(2*Sigma**2))*(1-SURVIVAL1)-(exp(-(k-alpha1*timec)**2/2*Sigma**2))*(k*alpha1-alpha1**2*timec)*(1-SURVIVAL1)-ht_sum;

solve timec satisfy=(UU) / data=test(where=(t)) out=testOut;

run;

proc sql;

create table testSol as

select * from test natural left join testOut

order by time;

select * from testsol;

quit;

timetUUkalpha1SigmaSURVIVAL1ht_sumType of ObservationSolution ModeExecution Errortimecobs
Count
0.0005210.01840.50531.4570.233730.98510.01PREDICTSIMULATE061
0.0006910.03840.30531.4570.233730.98510.01PREDICTSIMULATE04.43
0.0006900.01840.20531.4570.233730.98510.01..2
0.0017800.02840.10531.4570.233730.98510.01..4
Super Contributor
Posts: 303

Re: Proc model solve for X preserving sample size

Posted in reply to desireatem

Hello , Is there a way that I can force a value for timec when it is closed but not exact? This is because I need value for data point

Ask a Question
Discussion stats
  • 14 replies
  • 446 views
  • 0 likes
  • 3 in conversation