Computes densities of observations in parameterized MVN mixtures.

dens(data, modelName, parameters, logarithm = FALSE, warn=NULL, ...)

Arguments

data

A numeric vector, matrix, or data frame of observations. Categorical variables are not allowed. If a matrix or data frame, rows correspond to observations and columns correspond to variables.

modelName

A character string indicating the model. The help file for mclustModelNames describes the available models.

parameters

The parameters of the model:

pro

The vector of mixing proportions for the components of the mixture.

mean

The mean for each component. If there is more than one component, this is a matrix whose kth column is the mean of the kth component of the mixture model.

variance

A list of variance parameters for the model. The components of this list depend on the model specification. See the help file for mclustVariance for details.

logarithm

A logical value indicating whether or not the logarithm of the component densities should be returned. The default is to return the component densities, obtained from the log component densities by exponentiation.

warn

A logical value indicating whether or not a warning should be issued when computations fail. The default is warn=FALSE.

...

Catches unused arguments in indirect or list calls via do.call.

Value

A numeric vector whose ith component is the density of the ith observation in data in the MVN mixture specified by parameters.

Examples

# \donttest{
faithfulModel <- Mclust(faithful)
Dens <- dens(modelName = faithfulModel$modelName, data = faithful,
             parameters = faithfulModel$parameters)
Dens
#>            1            2            3            4            5            6 
#> 0.0122707769 0.0250791544 0.0043706519 0.0138530357 0.0382956210 0.0002669332 
#>            7            8            9           10           11           12 
#> 0.0202191254 0.0040575505 0.0301848769 0.0325465898 0.0276869342 0.0127084049 
#>           13           14           15           16           17           18 
#> 0.0362272836 0.0126473322 0.0340433096 0.0275448001 0.0053347162 0.0232973040 
#>           19           20           21           22           23           24 
#> 0.0107378357 0.0408143520 0.0238107781 0.0126473322 0.0072401212 0.0004615756 
#>           25           26           27           28           29           30 
#> 0.0203636678 0.0066803862 0.0348709952 0.0258863865 0.0209955144 0.0477227189 
#>           31           32           33           34           35           36 
#> 0.0206531762 0.0391333267 0.0014780594 0.0257972930 0.0167084263 0.0332636318 
#>           37           38           39           40           41           42 
#> 0.0187479804 0.0175051886 0.0163036777 0.0109972466 0.0474204872 0.0227110075 
#>           43           44           45           46           47           48 
#> 0.0415680246 0.0137115191 0.0158266993 0.0012729444 0.0010299378 0.0336507731 
#>           49           50           51           52           53           54 
#> 0.0409197701 0.0251395735 0.0086303933 0.0127443256 0.0276869342 0.0175051886 
#>           55           56           57           58           59           60 
#> 0.0195757229 0.0158547822 0.0099200538 0.0015967934 0.0333010021 0.0448831115 
#>           61           62           63           64           65           66 
#> 0.0239559246 0.0428496246 0.0149845645 0.0234478154 0.0124655190 0.0057207553 
#>           67           68           69           70           71           72 
#> 0.0340808379 0.0254708050 0.0064351071 0.0084682320 0.0220153547 0.0332770111 
#>           73           74           75           76           77           78 
#> 0.0459430980 0.0104506735 0.0132065431 0.0014619324 0.0217586659 0.0378862342 
#>           79           80           81           82           83           84 
#> 0.0205889086 0.0066803862 0.0250386851 0.0438577789 0.0085574647 0.0017709761 
#>           85           86           87           88           89           90 
#> 0.0168201235 0.0088830496 0.0218162889 0.0476014546 0.0138720624 0.0099493552 
#>           91           92           93           94           95           96 
#> 0.0221772274 0.0094489614 0.0250152660 0.0146789904 0.0059518823 0.0162549604 
#>           97           98           99          100          101          102 
#> 0.0355225683 0.0172825304 0.0275228747 0.0139559513 0.0071018356 0.0183366060 
#>          103          104          105          106          107          108 
#> 0.0203532755 0.0463634341 0.0251129031 0.0154593959 0.0327309413 0.0238013515 
#>          109          110          111          112          113          114 
#> 0.0166081728 0.0125494369 0.0124071667 0.0205249659 0.0088890790 0.0477608953 
#>          115          116          117          118          119          120 
#> 0.0087337354 0.0404200470 0.0118739090 0.0365574562 0.0153237485 0.0254418777 
#>          121          122          123          124          125          126 
#> 0.0028285242 0.0062235544 0.0367698291 0.0332770111 0.0228631638 0.0152445746 
#>          127          128          129          130          131          132 
#> 0.0096078262 0.0485643201 0.0257527006 0.0138710618 0.0095366375 0.0275045523 
#>          133          134          135          136          137          138 
#> 0.0007572071 0.0128224853 0.0119541984 0.0467697878 0.0282281324 0.0109926682 
#>          139          140          141          142          143          144 
#> 0.0352702703 0.0171467325 0.0384053159 0.0211703981 0.0475772253 0.0122779718 
#>          145          146          147          148          149          150 
#> 0.0355556985 0.0244886753 0.0386518809 0.0228345796 0.0004696987 0.0254619048 
#>          151          152          153          154          155          156 
#> 0.0025750274 0.0244958403 0.0051819355 0.0434023375 0.0082005926 0.0080988362 
#>          157          158          159          160          161          162 
#> 0.0492461255 0.0011143717 0.0254619048 0.0037325233 0.0051808630 0.0155405861 
#>          163          164          165          166          167          168 
#> 0.0288468099 0.0205963766 0.0021521139 0.0271890898 0.0092240733 0.0060951894 
#>          169          170          171          172          173          174 
#> 0.0322175567 0.0054955650 0.0230753789 0.0332492684 0.0320539198 0.0021292353 
#>          175          176          177          178          179          180 
#> 0.0330200275 0.0459247107 0.0171264585 0.0068465199 0.0125125545 0.0226037644 
#>          181          182          183          184          185          186 
#> 0.0302872440 0.0320539198 0.0340958190 0.0112216922 0.0300605795 0.0444833129 
#>          187          188          189          190          191          192 
#> 0.0188389127 0.0119541984 0.0451826484 0.0318305057 0.0224060120 0.0222103090 
#>          193          194          195          196          197          198 
#> 0.0109726952 0.0197480537 0.0234588094 0.0384053159 0.0012583227 0.0405029646 
#>          199          200          201          202          203          204 
#> 0.0188536746 0.0287510417 0.0232604940 0.0449585388 0.0031753778 0.0302271931 
#>          205          206          207          208          209          210 
#> 0.0351137802 0.0110771907 0.0405130102 0.0110738013 0.0232544418 0.0463634341 
#>          211          212          213          214          215          216 
#> 0.0005925546 0.0315289486 0.0220102694 0.0184806555 0.0009023966 0.0325656419 
#>          217          218          219          220          221          222 
#> 0.0126143782 0.0032201571 0.0358732599 0.0288218671 0.0250152660 0.0388430888 
#>          223          224          225          226          227          228 
#> 0.0209701825 0.0278737826 0.0252166485 0.0313864902 0.0290215102 0.0403560942 
#>          229          230          231          232          233          234 
#> 0.0079947124 0.0430006133 0.0084615742 0.0127969899 0.0172641330 0.0179025070 
#>          235          236          237          238          239          240 
#> 0.0125562378 0.0312429480 0.0289616059 0.0382686642 0.0232927036 0.0079999951 
#>          241          242          243          244          245          246 
#> 0.0256640045 0.0046569310 0.0109926682 0.0002941915 0.0372016212 0.0151319087 
#>          247          248          249          250          251          252 
#> 0.0332492684 0.0459498689 0.0034327330 0.0255597331 0.0297690462 0.0461172111 
#>          253          254          255          256          257          258 
#> 0.0107096177 0.0171264585 0.0093189544 0.0183858540 0.0101940749 0.0461172111 
#>          259          260          261          262          263          264 
#> 0.0344591262 0.0429864494 0.0190147184 0.0425259106 0.0205065804 0.0340958190 
#>          265          266          267          268          269          270 
#> 0.0047576298 0.0205470761 0.0113825738 0.0292875446 0.0085827041 0.0117658465 
#>          271          272 
#> 0.0117107647 0.0232041075 

## alternative call
do.call("dens", faithfulModel)# }
#>            1            2            3            4            5            6 
#> 0.0122707769 0.0250791544 0.0043706519 0.0138530357 0.0382956210 0.0002669332 
#>            7            8            9           10           11           12 
#> 0.0202191254 0.0040575505 0.0301848769 0.0325465898 0.0276869342 0.0127084049 
#>           13           14           15           16           17           18 
#> 0.0362272836 0.0126473322 0.0340433096 0.0275448001 0.0053347162 0.0232973040 
#>           19           20           21           22           23           24 
#> 0.0107378357 0.0408143520 0.0238107781 0.0126473322 0.0072401212 0.0004615756 
#>           25           26           27           28           29           30 
#> 0.0203636678 0.0066803862 0.0348709952 0.0258863865 0.0209955144 0.0477227189 
#>           31           32           33           34           35           36 
#> 0.0206531762 0.0391333267 0.0014780594 0.0257972930 0.0167084263 0.0332636318 
#>           37           38           39           40           41           42 
#> 0.0187479804 0.0175051886 0.0163036777 0.0109972466 0.0474204872 0.0227110075 
#>           43           44           45           46           47           48 
#> 0.0415680246 0.0137115191 0.0158266993 0.0012729444 0.0010299378 0.0336507731 
#>           49           50           51           52           53           54 
#> 0.0409197701 0.0251395735 0.0086303933 0.0127443256 0.0276869342 0.0175051886 
#>           55           56           57           58           59           60 
#> 0.0195757229 0.0158547822 0.0099200538 0.0015967934 0.0333010021 0.0448831115 
#>           61           62           63           64           65           66 
#> 0.0239559246 0.0428496246 0.0149845645 0.0234478154 0.0124655190 0.0057207553 
#>           67           68           69           70           71           72 
#> 0.0340808379 0.0254708050 0.0064351071 0.0084682320 0.0220153547 0.0332770111 
#>           73           74           75           76           77           78 
#> 0.0459430980 0.0104506735 0.0132065431 0.0014619324 0.0217586659 0.0378862342 
#>           79           80           81           82           83           84 
#> 0.0205889086 0.0066803862 0.0250386851 0.0438577789 0.0085574647 0.0017709761 
#>           85           86           87           88           89           90 
#> 0.0168201235 0.0088830496 0.0218162889 0.0476014546 0.0138720624 0.0099493552 
#>           91           92           93           94           95           96 
#> 0.0221772274 0.0094489614 0.0250152660 0.0146789904 0.0059518823 0.0162549604 
#>           97           98           99          100          101          102 
#> 0.0355225683 0.0172825304 0.0275228747 0.0139559513 0.0071018356 0.0183366060 
#>          103          104          105          106          107          108 
#> 0.0203532755 0.0463634341 0.0251129031 0.0154593959 0.0327309413 0.0238013515 
#>          109          110          111          112          113          114 
#> 0.0166081728 0.0125494369 0.0124071667 0.0205249659 0.0088890790 0.0477608953 
#>          115          116          117          118          119          120 
#> 0.0087337354 0.0404200470 0.0118739090 0.0365574562 0.0153237485 0.0254418777 
#>          121          122          123          124          125          126 
#> 0.0028285242 0.0062235544 0.0367698291 0.0332770111 0.0228631638 0.0152445746 
#>          127          128          129          130          131          132 
#> 0.0096078262 0.0485643201 0.0257527006 0.0138710618 0.0095366375 0.0275045523 
#>          133          134          135          136          137          138 
#> 0.0007572071 0.0128224853 0.0119541984 0.0467697878 0.0282281324 0.0109926682 
#>          139          140          141          142          143          144 
#> 0.0352702703 0.0171467325 0.0384053159 0.0211703981 0.0475772253 0.0122779718 
#>          145          146          147          148          149          150 
#> 0.0355556985 0.0244886753 0.0386518809 0.0228345796 0.0004696987 0.0254619048 
#>          151          152          153          154          155          156 
#> 0.0025750274 0.0244958403 0.0051819355 0.0434023375 0.0082005926 0.0080988362 
#>          157          158          159          160          161          162 
#> 0.0492461255 0.0011143717 0.0254619048 0.0037325233 0.0051808630 0.0155405861 
#>          163          164          165          166          167          168 
#> 0.0288468099 0.0205963766 0.0021521139 0.0271890898 0.0092240733 0.0060951894 
#>          169          170          171          172          173          174 
#> 0.0322175567 0.0054955650 0.0230753789 0.0332492684 0.0320539198 0.0021292353 
#>          175          176          177          178          179          180 
#> 0.0330200275 0.0459247107 0.0171264585 0.0068465199 0.0125125545 0.0226037644 
#>          181          182          183          184          185          186 
#> 0.0302872440 0.0320539198 0.0340958190 0.0112216922 0.0300605795 0.0444833129 
#>          187          188          189          190          191          192 
#> 0.0188389127 0.0119541984 0.0451826484 0.0318305057 0.0224060120 0.0222103090 
#>          193          194          195          196          197          198 
#> 0.0109726952 0.0197480537 0.0234588094 0.0384053159 0.0012583227 0.0405029646 
#>          199          200          201          202          203          204 
#> 0.0188536746 0.0287510417 0.0232604940 0.0449585388 0.0031753778 0.0302271931 
#>          205          206          207          208          209          210 
#> 0.0351137802 0.0110771907 0.0405130102 0.0110738013 0.0232544418 0.0463634341 
#>          211          212          213          214          215          216 
#> 0.0005925546 0.0315289486 0.0220102694 0.0184806555 0.0009023966 0.0325656419 
#>          217          218          219          220          221          222 
#> 0.0126143782 0.0032201571 0.0358732599 0.0288218671 0.0250152660 0.0388430888 
#>          223          224          225          226          227          228 
#> 0.0209701825 0.0278737826 0.0252166485 0.0313864902 0.0290215102 0.0403560942 
#>          229          230          231          232          233          234 
#> 0.0079947124 0.0430006133 0.0084615742 0.0127969899 0.0172641330 0.0179025070 
#>          235          236          237          238          239          240 
#> 0.0125562378 0.0312429480 0.0289616059 0.0382686642 0.0232927036 0.0079999951 
#>          241          242          243          244          245          246 
#> 0.0256640045 0.0046569310 0.0109926682 0.0002941915 0.0372016212 0.0151319087 
#>          247          248          249          250          251          252 
#> 0.0332492684 0.0459498689 0.0034327330 0.0255597331 0.0297690462 0.0461172111 
#>          253          254          255          256          257          258 
#> 0.0107096177 0.0171264585 0.0093189544 0.0183858540 0.0101940749 0.0461172111 
#>          259          260          261          262          263          264 
#> 0.0344591262 0.0429864494 0.0190147184 0.0425259106 0.0205065804 0.0340958190 
#>          265          266          267          268          269          270 
#> 0.0047576298 0.0205470761 0.0113825738 0.0292875446 0.0085827041 0.0117658465 
#>          271          272 
#> 0.0117107647 0.0232041075